You are here: Re: how does php parse actually this? « PHP Programming Language « IT news, forums, messages
Re: how does php parse actually this?

Posted by Andy Hassall on 05/14/05 14:34

On Sat, 14 May 2005 04:59:01 GMT, boclair <boclair@bigpond.net.au> wrote:

>> It's valid - it's the "alternative control structure syntax".
>>
>> <?php if ($something) : ?>
>>
>> stuff goes here
>>
>> <?php endif; ?>

>I ceased using this syntax a couple of years ago having been instructed
>that it was outdated, PHP peculiar and likely to be dropped in later
>versions of PHP. Was this wrong? It certainly produces cleaner
>scripting on occasion.

I don't recall ever reading anything implying it'd be dropped, and it's still
there in PHP5. There's no warnings to this effect in the manual that I can see.

It would be incredibly foolish of the PHP maintainers to drop this since it'll
simply break scripts, with no actual benefit to removing the functionality.

Where did you hear this information? I've found this article:

http://www.zend.com/zend/art/mistake.php?article=mistake&kind=a&id=2022&open=1&anc=0&view=1#Heading23

Which says:

" * It is not widely used, and therefore, many people learning the language
will be confused by the two syntaxes. "

There are many built-in functions that are not widely used, but that shouldn't
stop you using the appropriate one for the task in hand. The alternative
structure syntax has a particular niche in the type of output posted earlier;
it's not much good in blocks of PHP (as in the article), but it's useful in
specific situations. I'd argue that:

<?php } ?>

... confuses new starters more than:

<?php endif; ?>

... in the "conditional around blocks of literal text" situation.


" * It is not compatible with other languages, meaning that it is harder to
read for people who are transitioning. "

So? PHP's not compatible with Python's method of control structures either.

(And what will people be transitioning from, anyway? ASP? In which case -
they'll prefer endif...)


" * Most importantly, someday in the future it might be disabled, forcing you
to rewrite the code that implemented it. Brackets, however, will always be a
part of the PHP language. "

Without a reference to a documented warning that it's deprecated, this doesn't
count. The article was written in 2000, five years later they're still there
and still useful in a very specific situation.

There are deprecated features in PHP, such as accessing characters within a
string using [] instead of {} ($string[1] is deprecated but works, $string{1}
is supposed to be the way to go). This is documented:

http://uk2.php.net/manual/en/language.types.string.php#language.types.string.substr

They say it's deprecated in PHP4, so they'd have some leeway for removing it
in PHP5. They haven't though.

I see no similar warning for the alternative control structure syntax. I'm
certainly not going to stop using it in the specific situations where it is
more readable.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

 

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

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