I am developer of imi-conrun and have a problem: We use the psySh package we would like not to drop and defines the global scope function "dump" and have to initialize the Contao core which defines the global scope function "dump" as well without checking if the function is registered and then crashes.
Is there any possibility to only remove the dump function from psySh without making a fork?
I think there is no real solution for this.
In the end it turn's out I do not need PsySH - so I removed it - problem solved.
Might make the suggestion to Contao to not blindly defined the dump function without a function_exists() call
On the other hand I could ensure that Contao is loaded first, then PsySH and thus would not define the dump() function again which would mean to run the composer autoload before the Contao init.
TL;DR: global name space functions are bad.
Related
I'm trying to create a service where a user needs to operate over a data and can manipulate it in numerous ways, so I'm not aware of the manipulations at the time of compiling of my program. One way to achieve this is to give the user a function with data as param. Which landed me in the following direction.
Dynamically create a function
Dynamically linking a function after compiling it separately.
I'm open to suggestions. If you have other ways to achieve the end goal.
If you don't like this as an answer I can move to the comment section, but it's rather long that's why I put here in the answer section.
Dynamically Dispatched Method: The only way to have dynamically dispatched methods is through an interface. Methods on a struct or any other concrete type are always resolved statically.
Closure: Go supports anonymous functions, which can form closures. Anonymous functions are useful when you want to define a function inline without having to name it.
Dyncamically call method on Interface:
Please let me know if that helps you to understand the concept in golang.
We had Forify scan for our website code and fortify reported few issues. We are using CodeIgniter 3.1.9 framework. One of the issue they mentioned as
Possible Variable Overwrite' for function 'extract()' in file mysqli_utility.php.
As this is core file of CI framework, I'm not using this function directly and also I do not know where this function getting used by CI.
Will you please help to resolve the issue reported by Fortify? What could be the solution?
extract() imports variables from an array into the current symbol table. The phrase "current symbol table" basically means into the current scope of the code. For the usage in question, extract() is called inside a class method. So the current scope for the extracted vars will be in that method and that method only for that instance of the class.
CodeIgniter's core code does not define or use global variables. Unless code developed for the application uses globals (which it should not as "globals" are more of a "procedural programming" thing) the possibility of overwriting is exceedingly low.
I'm curious as to why the scan didn't pick up all the other times extract is used by CodeIgniter.
I write a library, this library includes a function void f() this function is a one line function and when I compile the library to shared object with -O3 gcc optimization flag it is inlined. I call it in a critical place in the code (must be as fast as possible) and I don't want to call it not inlined (hits performance substantially). The problem is that this function is part of the API that my library exposes so when library users link with my library and call this function they get undefined reference linkage error. Is there a way for my code to use the function inlined but still instantiate it in the object file so library users will be able to link and use it? (When I say "instantiate it in the object file" I mean I'd like to see it when I run objdump -t on the shared object). Just to make it clear, I'm not interested in a solution to wrap it with a function
void F() __attribute__((noinline)) { f(); }
Because I have many functions like that and I don't want to keep a copy for every function due to the enormous amount of overhead. I'm looking for a way to tell the compiler to use it inline when the definition is available to it, but still instantiate the function in the object file, so library users can link to with it too.
Check out this How can I tell gcc not to inline a function?
I found this solution the most appropriate. I'd like to note the main thing is that the code inside the library is still inlined so there is no performance penalty but users can still use the API as all functions have instantiation
Also another possible solution in the compilation level is to use -fkeep-inline-functions gcc switch which also instantiates inline functions and and uses them inlined where possible (unlike -fno-inline switch). The main problem with this switch is that if your code is heavily templated compilation time is much longer and the binary product becomes much bigger
There is a method in code igniter under system/core/Common.php called load_class().
I would like to overwrite this method. Usually to overwrite a code igniter class I create a file such as MY_Common.php however in this case Common.php is a collection of methods and there are no classes that encapsulates them.
So how exactly do I do this?
There's no officially supported way to do this by the built in extending mechanisms. Consider some other way to achieve your goal.
However the functions inside Common.php are all wrapped inside an if checking if the function is already exists or not so you can do the following:
Create your MY_Common.php put somewhere in your project (maybe application/core/ to mirror other similar extends)
Open your index.php file in the root of the project
insert include APPPATH.'core/MY_Common.php'; before the closing require_once BASEPATH.'core/CodeIgniter.php'; line
Now if you have you have a load_class function in your MY_Common.php it will shadow the original version.
The correct/official way to do that is overwriting the core common function into ie. common_helper.php application/helpers and setting up in config/autoload.php
I implemented a rollback mechanism for my php execution so if an error occurs it will pop a stack and undo actions. How can I add this hook so my function is called anytime show_error is used?
Actually there is no such hook available.You need to hack it.
Modify the function "show_error()" in CI_Exceptions class (File: system/libraries/Exceptions.php) as per your Requirement.
This should be a reference to start with.
Update:
You should extent CI_Exceptions rather then modifying in-place.