Page 1 of 1

Register and Login (User Account System)

Posted: Wed Oct 03, 2012 6:48 pm
by jkmca
I'm fairly new to programming and am not sure what this error means.

"PHP Strict Standards: Only variables should be passed by reference in /Users/user/Sites/Main/Tutorial/core/init.inc.php on line 7
Here is the line 7 that it is referring to."
$page = substr(end(explode('/', $_SERVER ['SCRIPT_NAME'])), 0, -4);
I've checked the video multiple times and cannot figure out where my mistake is.
Thanks for your help.

Re: Register and Login (User Account System)

Posted: Wed Oct 03, 2012 9:26 pm
by jkmca
nevermind, I just added an extra step.
$exploded = explode('/', $_SERVER['SCRIPT_NAME']);
$page = substr(end($exploded), 0, -4);
If someone can explain why I had to do this, or if there is an easier way to do it, please let me know.
Thanks

Re: Register and Login (User Account System)

Posted: Wed Oct 10, 2012 7:43 pm
by jacek
The end() functions takes a reference to the variable as it's parameter, this means that it works with the actual variable instead of just the value. If we made a function like this
function double_value(&$value){
    $value *= 2;
}
And used it like this
$number = 10;

double_value($number);

// HERE
Where I have commented //HERE the variable $number will contain the value 20 if we did the same thing with this function
function double_value($value){
    $value *= 2;
}
it would still be 10 since the value is only modified inside the function.

The error is php complaining because you did not give it a variable for that function, meaning it cannot use the reference (since there is none). It does not matter though since it falls back to the value and works fine so you can just disable these messages.
error_reporting(E_ALL & ~E_STRICT);
or in your php.ini file
error_reporting = E_ALL & ~E_STRICT
:)