Register and Login (User Account System)

Post here is you are having problems with any of the tutorials.
Post Reply
jkmca
Posts: 2
Joined: Wed Oct 03, 2012 6:39 pm

Register and Login (User Account System)

Post 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.
jkmca
Posts: 2
Joined: Wed Oct 03, 2012 6:39 pm

Re: Register and Login (User Account System)

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Register and Login (User Account System)

Post 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
:)
Image
Post Reply