Page 1 of 1
PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 9:33 pm
by twiggy
Ok I'm working through the PHP login series and on the first video I ran in to a problem writing:
echo end(explode('/', $_SERVER['SCRIPT_NAME']));
It gave me this error:
Strict Standards: Only variables should be passed by reference in C:\xampp\htdocs\user_system\core\init.inc.php on line 5
protected.php
Of course it still returned the protected.php part but gives an error, after a bit of reading I found that newer versions of PHP a reference has to be a variable.
I will work on this and get back to you all on it, or maybe i should sit it out and this gets fixed later in the tutorial?
Re: PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 9:37 pm
by jacek
PHP wants you to do this.
$split = explode('/', $_SERVER['SCRIPT_NAME']);
echo end($split);
But passing functions as arguments is so convenient that I would just disable this error level.
Re: PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 9:47 pm
by twiggy
Yeah that works grate thanks!
Without trying to poke a stick in a hornets nest, would It be wise to carry on doing it the way PHP wants us to, in strict mode, or is it just not worth the hassle and disable it?
Re: PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 9:50 pm
by twiggy
For anyone following this at a later date and wants to give this ago here is the code for the next part of the tutorial:
<?php
session_start();
$split = explode('/', $_SERVER['SCRIPT_NAME']);
$page_title = substr(end($split), 0 ,-4);
?>
Then simply call
<?php echo $page_title ?> when ever you need the page title.
Re: PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 9:58 pm
by jacek
twiggy wrote:would It be wise to carry on doing it the way PHP wants us to, in strict mode, or is it just not worth the hassle and disable it?
Well there does not seem to be a performance difference, so I'm not entirely sure why php prefers you not to pass functions like that. I work with those errors hidden. I guess it's up to you
Re: PHP Login Strict Standards error
Posted: Mon Jun 13, 2011 10:11 pm
by twiggy
Hmm I will decide that once I know and understand more about PHP, I guess there is thought behind it, rite or wrong.
I'm just thinking a head in to the future when I share my scripts and pass them around I will want to make sure they work across many environments and platforms as possible so it looks like it could be worth me researching in to E_STRICT and E_ALL to show any possible conflicts in my code. Any thoughts on this welcome
Re: PHP Login Strict Standards error
Posted: Tue Jun 14, 2011 12:32 am
by jacek
twiggy wrote:Any thoughts on this welcome
You can set the error_reporting level in the script itself using the error_reporting() function. And it's still up to you, like you say there must be some reason for the messages so if you don't find it too much of a pain I guess it is a good idea to follow them.