Re: Redundant isset() check?

From: Date: Tue, 04 Nov 2014 12:07:35 +0000
Subject: Re: Redundant isset() check?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-324032@lists.php.net to get a copy of this message
On Tue, Nov 4, 2014 at 1:34 PM, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote: > You nearly had it, it should be something like: > > if ( !isset($_SERVER['DOCUMENT_ROOT']) && > !isset($connection_details[$_SERVER['DOCUMENT_ROOT']]) ) { > > The reason for && and not || is that an kr can still fail on > $_SERVER'[DOCUMENT_ROOT'] being set and still try to use it in the second part of the > if(). The and will only return true if both are set. > > have you tested with warnings turned on (as they should be on every development environment) > and tested with a non-existent $_SERVER array element? > Thank you. At the point as which I asked the development code is not yet written. On other projects I have done the initial (possibly redundant) isset() check properly using &&, but for this mailing list question I accidentally used ||. I agree, proper unit testing discipline would have caught that! That you for letting me know that the check is not redundant. I do prefer to have warnings turned on but not displayed to users on production systems, of course! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com

« previous php.general (#324032) next »