[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] Redundant isset() check?
From:       Dotan Cohen <dotancohen () gmail ! com>
Date:       2014-11-04 12:07:35
Message-ID: CAKDXFkMQFd-5Z3ZzU5FWozTk27J0zW3pZC-i-m3yMyEce3b3FQ () mail ! gmail ! com
[Download RAW message or body]

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic