Page 1 of 1
Only variables should be passed by reference ??
Posted: Tue Aug 05, 2008 8:26 am
by Stryks
I've just upped my development environment to strict notice reporting, and I'm finding what seems a weird error popping up. Probably simple ... it's late and I'm sure I've got some fuzzy thinking going on.
The following code is giving "ERROR: E_Strict - Only variables should be passed by reference.
Code: Select all
$CURRENT_PAGE = array("NAME"=>end(explode("/",$_SERVER["SCRIPT_NAME"])), "AUTH_LEVEL"=>0, "SSL"=>false);
Am I missing something here?
Thanks
Re: Only variables should be passed by reference ??
Posted: Tue Aug 05, 2008 8:36 am
by Stryks
Okay ... changing that to ...
Code: Select all
$CURRENT_PAGE = "";
$CURRENT_PAGE = array("NAME"=>(end(explode("/",$_SERVER["SCRIPT_NAME"]))), "AUTH_LEVEL"=>0, "SSL"=>false);
... fixed it.
Not really sure what the significance of that is.
Can anyone explain this ... and why it might be important?
Cheers all.

Re: Only variables should be passed by reference ??
Posted: Tue Aug 05, 2008 11:22 am
by alex.barylski
Weird. Not the error so much as the solution to fix it.
Code: Select all
end(explode("/",$_SERVER["SCRIPT_NAME"]))
end() expects an array by reference but it's getting the results of a function which while it's returning an array you cannot pass a function result as an argument to a function that is expecting a variable which it can then reference.
Basically
end() is expecting a reference to a variable which it can then adjust accordingly but because you pass in a function which returns a temporary variable (it's not available in the context of end())
end() cannot actually update the reference properly and thus you are getting an error.
Code: Select all
$tmp = explode("/", $_SERVER["SCRIPT_NAME"]);
end($tmp);
This will correct the error -- correctly!!!

Re: Only variables should be passed by reference ??
Posted: Wed Aug 06, 2008 2:03 am
by Stryks
Ahh .... NOW it makes sense.
And you're right ... the workaround I fluked IS weird. Anyhow, I understand how to do it correctly now.
Many thanks.
