-2

I keep receiving the error:

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)

This is line 10

if (isset($_GET['page']=="logout")) {

Here's the "entire" part of that code:

    session_destroy();
    echo '<script>document.location.href="shipper.php"</script>';

}
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • You could have searched for this error, really. The first hit I got from doing a Google search, was the duplicate I used to close the question with. – Funk Forty Niner Dec 22 '18 at 02:27

2 Answers2

1

isset() doesn't work this way. It only checks if something exist, but never a value. You can do

<?php
    if(isset($_GET['something'] && $_GET['something'] === "value"){
             //do something
    }
?>
Dice
  • 236
  • 1
  • 8
-1

isset is a function that you pass a value to in order to determine if that variable has been set. You don't put an equality expression in it.

You could do this:

if (isset($_GET['page']) && $_GET['page'] == 'logout') {

or simply:

if ($_GET['page'] == 'logout') {

Side note... if you're doing a literal string (with no variables in it) you should just use single quotes. (note I changed that above)

Jason Byrne
  • 1,579
  • 9
  • 19
  • 1. Your second suggestion will generate an "Undefined Index" notice and shouldn't be used. 2. There is no functional difference between double and single quotes on static strings and there's no reason that someone "should" use one or the other in such a simple case. – Sammitch Dec 22 '18 at 01:51
  • Single quote has better performance because PHP doesn't have to interpret variables inside of it. So, yes, there is a reason. If it's a string literal then use single quote. – Jason Byrne Dec 22 '18 at 02:21
  • No they don't. Not in any meaningful way. The amount of time someone might spend briefly contemplating using one quote or the other has already taken orders of magnitude more time than they will ever collectively save over the course of their life save by using a different quote to encapsulate a string. – Sammitch Dec 22 '18 at 05:34
  • Definitively you are incorrect. If not doing it for the slight performance edge, you should do it to be in line with accepted best practices in the industry, as well as being a disciplined coder and actually thinking about what you are trying to accomplish. Knowing if you're doing a string literal or a string that needs to be parsed is an important discipline and becomes second nature to mature programmers. See the Zend standards, for example: https://framework.zend.com/manual/2.4/en/ref/coding.standard.html#string-literals – Jason Byrne Dec 22 '18 at 05:45
  • Oh here we go: https://phpbench.com/ You _might_ save six _picoseconds_ if you're encapsulating an empty string, assuming that that's not just the margin of error. Stop spreading bad info like this. – Sammitch Dec 22 '18 at 05:54
  • And Zend's coding standard has zero bearing on performance. It's a _style guide_ specific to that project. – Sammitch Dec 22 '18 at 05:56
  • I'm sure you'll say WordPress standards don't matter either: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#single-and-double-quotes – Jason Byrne Dec 22 '18 at 05:59
  • Basically ANY standard best practices is gonna tell you the same. And if you join a team worth a darn they will insist on it. They'll apply php linters to insist on it. Just trying to help people better their skills to be in line with industry standards and best practices. – Jason Byrne Dec 22 '18 at 06:00
  • "I'm sure you'll say WordPress standards don't matter either" Thank you for the genuine laugh out loud. It's not often that I see someone seriously use the words "Wordpress" and "standards" in the same sentence. Once again: That's still a _style guide_ and has _no_ bearing on performance. It's there so everyone's code _looks the same_ and it's easier to collaborate on. I don't give a flying fornication what quote you use, but I will absolutely shout down anyone that tries to tell people that single quotes are in any way more efficiently executed than double quotes. – Sammitch Dec 22 '18 at 06:15
  • Alright man, well we can shut this debate down. The performance difference is there, but admittedly negligible. But, my point is, pretty much any project worth its salt is gonna agree and pretty much any respectable PHP development team I have ever been associated with. Final point I'll make sure I drive home is they are inherently function differently. Single quote is a literal. It will not parse variables within it. Double quotes will. So they have different purposes. And, in my opinion, it is always best to be intentional in your code. Obviously, you won't agree. Goodnight. – Jason Byrne Dec 22 '18 at 06:21