Is codeigniter 2.1 PHP 5.4 compatible ? |
[eluser]skunkbad[/eluser]
[quote author="WanWizard" date="1342867030"]If E_STRICT is on and you're on PHP 5.4, this line will fail with a decprecated error: https://github.com/EllisLab/CodeIgniter/...r.php#L161. You can no longer assign the return value of a function by reference (unless you take special precautions). In earlier 2.x versions, this line is in core/common.php. As at this point nothing is loaded yet, you can replace the line by Code: $this->_base_classes = false; WW, I'm not running php5.4, but interested in this, so I checked CI 2.1.1 and was wondering if the fix was to remove the ampersand before the function name? Code: function &load;_class( ...
[eluser]WanWizard[/eluser]
skunkbad, No, you can't remove the ampersand from load_class(), that function does need to return by reference. It's the result of is_loaded() that is returned by value, but assigned to $this->_base_classes by reference that causes the error. I don't know why that is there, as in the initialisation nothing is loaded yet.
[eluser]skunkbad[/eluser]
[quote author="WanWizard" date="1342886881"]skunkbad, No, you can't remove the ampersand from load_class(), that function does need to return by reference. It's the result of is_loaded() that is returned by value, but assigned to $this->_base_classes by reference that causes the error. I don't know why that is there, as in the initialisation nothing is loaded yet.[/quote] Somebody should submit a pull request... I did read the php docs on references, but it's still sort of foggy to me. I guess the point of using a reference is so that extra memory isn't used to hold a value, right? The basic examples in the php docs are easy enough to understand, but others I have to think, "why the heck would you want to do that?".
[eluser]WanWizard[/eluser]
If you assign something by value, PHP will make a copy of it as soon as it is changed. Code: $a = 1; If you assign by reference, both variables point to the same internal struct id, so changing one changes the other. It works a bit similar to pointers in C. Code: $a = 1; It gets more complicated if functions/methods are involved. In PHP < 5.4 you could have a function that returns by value, which you could assign to a value by reference by doing Code: function myfunc($var) { In PHP 5.4 this is deprecated and produces a warning, the function should define whether or not it returns by reference: Code: function & myfunc($var) { p.s. I haven't had time to send a pull request yet, it's on the todo...
[eluser]skunkbad[/eluser]
So, in CI, there are many places where the function "get_instance" is called by reference. Code: $CI =& get_instance(); Will all these be changed at some point? Code: $CI = get_instance();
[eluser]WanWizard[/eluser]
Eventually, yes. It is no longer supported after PHP 5.4.
[eluser]jorisw[/eluser]
To clarify, only _call time_ pass by reference is no longer supported as of PHP 5.4. In many regex examples on the web, you'll find a return value in a _function call_ prefixed with an ampersand: Code: preg_match('/^[\s>]+/i',$line,&$matches); However, stuff like: Code: $this->ci =& get_instance();
[eluser]rusman[/eluser]
I also have the like problem, version php5.4.20 version of CI 2.1.2, on php5.2.17 everything works, no error is shown only a blank page, how to understand what is the problem?
[eluser]rusman[/eluser]
my problem is over, php.ini was not configured correctly
[eluser]noideawhattotypehere[/eluser]
Im using it with 5.4.20 and have no problems. |
Welcome Guest, Not a member yet? Register Sign In |