You are here: Re: What does this mean? « All PHP « IT news, forums, messages
Re: What does this mean?

Posted by Oli Filth on 09/28/30 11:41

Jim Michaels said the following on 02/03/2006 21:48:
> "Oli Filth" <catch@olifilth.co.uk> wrote in message
> news:GitLf.59807$mf2.22726@newsfe6-win.ntli.net...
>> J.O. Aho said the following on 21/02/2006 00:30:
>>> Smiley wrote:
>>>>
>>>> $password = isset($HTTP_POST_VARS['password']) ?
>>>> $HTTP_POST_VARS['password'] : '';
>>>>
>>>> I have never seen the question mark or colon used in this way before. I
>>>> can't find any reference to it in my PHP book. Please tell me what it
>>>> means.
>>>
>>> It's a form of an if-statement...
>> Arrgh!! Don't say that!!!
>
> technicality. it works sort of like an if statement, but it evaluates to
> one of 2 values you specify, switched by the condition.
> Is that better?


The problem is that a lot of novices think X?A:B *is* shorthand for an
if {...} else {...}, and then we get questions like "Why doesn't this
work?":

$var ? { $a++; doSomething(); } : { doSomethingElse(); }


e.g.:
http://groups.google.com/group/comp.lang.php/browse_frm/thread/67551ccc0e0967f8
http://groups.google.com/group/comp.lang.php/browse_frm/thread/37d0659c09fe087d


--
Oli

 

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

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