On Wed, Aug 26, 2015 at 11:08 AM, Craig Francis <cr...@craigfrancis.co.uk>
wrote:

> On 26 Aug 2015, at 16:44, Stanislav Malyshev <smalys...@gmail.com> wrote:
>
> >> Depending on the website I may then add a key to define the
> >> 'report-uri', or I may set it to NULL to say that I don't want one.
> >
> > NULL is not the best value to for this, but the function you're looking
> > for is array_key_exists().
>
>
>
> What would be the best value?
>
> And the array_key_exists() function has already been mentioned (and is
> what I'm using... but I cut that bit out to keep the reply shorter, as
> mentioned in my previous email).
>
>
What I would do is use false to me I don't want this, and null/not set to
mean do the default, and a value to mean this is what I want. Then you end
up with:

if (!isset($val)) {
   // do the default
} elseif (!empty($val)) {
   // do something with $val
}
// else do nothing because I don't want this thing

On the other hand, if I'm designing something using null as a special case
value, then I would just use array_key_exists and is_null (these calls
exist a few times in my code) but generally speaking I try not to give null
special meaning.

Reply via email to