You are here: [case closed][Fwd: Re: [PHP-DEV] [Fwd: [PHP] constant() - php5]] « PHP « IT news, forums, messages
[case closed][Fwd: Re: [PHP-DEV] [Fwd: [PHP] constant() - php5]]

Posted by Jochem Maas on 07/01/05 23:13

thanks for that explanation, case closed. :-)

-------- Original Message --------
Return-Path: <internals-return-17063-jochem=iamjochem.com@lists.php.net>
X-Original-To: jochem@iamjochem.com
Subject: Re: [PHP-DEV] [Fwd: [PHP] constant() - php5]
X-Virus-Scanned: amavisd-new at moulin.nl

Due to PHPs dynamic typing, unquoted strings are treated as strings
unless a constant by that name exists. Thankfully it's clever enough to
raise a notice to tell you it couldn't find a constant by that name,
which makes debugging much easier.

The reason constant() throws a warning rather than a notice is because
PHP knows you're looking for a constant by that name and flags it as a
more serious error, wheras before, it could just be that you want to use
an unquoted string :)

If you think it's a bit strange, it may seem so, but logically, if an
unquoted number is equivilent to it's quoted counter-part, the same must
be true for strings.

Nicholas Telford

Jochem Maas wrote:
> Derick Rethans wrote:
>
>> On Fri, 1 Jul 2005, Jochem Maas wrote:
>>
>>
>>> echo constant('CNST');
>>>
>>> when:
>>>
>>> echo CNST;
>>>
>>> only triggers an E_NOTICE.
>>> (assuming, in both cases that CNST is not defined).
>>>
>>> IMHO it should at most trigger an E_NOTICE.
>>
>>
>>
>> Did you compare the output of the two statements?
>
>
> I did.
>
>> echo constant('CNST');
>> shows nothing (except the warning)
>>
>> echo CNST;
>> shows "CNST" (and a notice).
>>
>> This makes perfect sense to me to differentiate between them like this.
>
>
> ok - agreed that the echo behaviour is logical - but I wasn't actually
> pertaining to the echo behaviour (and what was being echo'ed wasn't
> relevant to my
> original question).
>
> my point is that using a constant directly in your code when that
> constant doesn't exist
> only causes an E_NOTICE but passing a string to constant() when a
> constant of the given
> name doesn't exist causes an E_WARNING.
>
> I would either expect both to cause the same level of error OR that
> trying to
> use an undefined constant directly in code would cause a lower level of
> error.
>
> but if you say the error output behaviour is expected/correct/desired
> then I'm
> happy to except it (and adjust my expectations accordingly)
> - if you (anyone) could explain why (because I don't grok the logic behind
> this behaviour) I would be very grateful, maybe it will bring me one
> step closer
> to being able to call myself a real programmer. :-/
>
> anyway thanks for taking the time to reply,
> I gather that you, Derick (amongst others!), have a plate full of PHP work
> in the form of unicode and date related stuff (which I am very much looking
> forward to!) - i.e. you are busy-busy, time is short, etc etc.
>
> kind rgds,
> Jochem
>
>
>>
>> Derick
>>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация