Welcome Guest, Not a member yet? Register   Sign In
Is codeigniter 2.1 PHP 5.4 compatible ?
#21

[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;
to get rid of the error.[/quote]

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( ...
#22

[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.
#23

[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?".
#24

[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;
$b = $a;
$a = 2;
var_dump($a, $b); // dumps 2, 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;
$b =& $a;
$a = 2;
var_dump($a, $b); // dumps 2, 2

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) {
    return $var;
}

$a =& myfunc($a);
it would make $a point to the same internal struct as $var (which is a copy of $a as it is passed by value to the function).

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) {
    return $var;
}

$a = myfunc($a);

p.s. I haven't had time to send a pull request yet, it's on the todo...
#25

[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();
#26

[eluser]WanWizard[/eluser]
Eventually, yes. It is no longer supported after PHP 5.4.
#27

[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);
The above line will trigger a fatal error under PHP 5.4 and kill the execution of your app.

However, stuff like:
Code:
$this->ci =& get_instance();
is not a call time reference and will work just fine under PHP 5.4.
#28

[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?
#29

[eluser]rusman[/eluser]
my problem is over, php.ini was not configured correctly
#30

[eluser]noideawhattotypehere[/eluser]
Im using it with 5.4.20 and have no problems.




Theme © iAndrew 2016 - Forum software by © MyBB