Re: Redundant isset() check?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 4, 2014 at 1:34 PM, Ashley Sheridan
<ash@xxxxxxxxxxxxxxxxxxxx> 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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux