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

List:       php-general
Subject:    Re: [PHP] Redundant isset() check?
From:       Ashley Sheridan <ash () ashleysheridan ! co ! uk>
Date:       2014-11-04 11:34:03
Message-ID: 7D8BCE50-FC6E-483F-85B7-E673D2D8B082 () ashleysheridan ! co ! uk
[Download RAW message or body]

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? 

On 4 November 2014 11:25:31 GMT+00:00, Dotan Cohen <dotancohen@gmail.com> wrote:
> Consider the situation where an application will use a different set
> of PDO connection details depending on which version of the site is
> running: production, dev, qa, cron job, etc. Considering that
> $_SERVER['DOCUMENT_ROOT'] may not be set, is this check sufficient:
> 
> if ( !isset( !isset($connection_details[$_SERVER['DOCUMENT_ROOT']]) ) {
> 
> Or would it be preferable to first check that
> $_SERVER['DOCUMENT_ROOT'] is set before relying on it:
> 
> if ( !isset($_SERVER['DOCUMENT_ROOT']) ||
> !isset($connection_details[$_SERVER['DOCUMENT_ROOT']]) ) {
> 
> The TRUE case of this if clause will simply use the default connection
> details:
> $connection_details[0]

Thanks,
Ash

-- 
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