PHP Login Strict Standards error

Post here is you are having problems with any of the tutorials.
Post Reply
twiggy
Posts: 58
Joined: Sat Jun 11, 2011 11:11 pm

PHP Login Strict Standards error

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

Re: PHP Login Strict Standards error

Post 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.
Image
twiggy
Posts: 58
Joined: Sat Jun 11, 2011 11:11 pm

Re: PHP Login Strict Standards error

Post 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?
twiggy
Posts: 58
Joined: Sat Jun 11, 2011 11:11 pm

Re: PHP Login Strict Standards error

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

Re: PHP Login Strict Standards error

Post 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 ;)
Image
twiggy
Posts: 58
Joined: Sat Jun 11, 2011 11:11 pm

Re: PHP Login Strict Standards error

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

Re: PHP Login Strict Standards error

Post 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.
Image
Post Reply