Reply to Re: php 4.4.1 constructor Vs. Php 5.0 constructor

Your name:

Reply:


Posted by Colin Fine on 12/08/05 11:38

Greg Scharlemann wrote:
> Thanks for the help. It looks like it's really just the public
> statement I had in front of __construct that was screwing everything
> up. In any case, I like the use of the class name over the user of
> __construct. I think it looks cleaner. Is there any advantage to using
> one over the other?
>
> greg
>
Yes.
The reason for the change is explained in "Upgrading to PHP5" Adam
Trachtenberg (O'Reilly), pp. 33-4:
"When constructors are tied to class names, it's easy to break code
without realizing it. In PHP4, to call the parent constructor inside of
your class, you must hardcode the parent class name. ....

"However, moving this class under a different parent, or even renaming
the parent, forces you to edie the constructor, replacing the call to
[parent::<classname> with parent::<new-classname>]."

Incidentally, Andy's suggestion will work, but is unnecessary. P. 23 of
the same book says:
"To ease the transition from PHP 4, if PHP 5 canot find a method names
__construct() within your object hierarchy, it revers to the PHP 4
constructor naming scheme and searches accordingly."

As you say, 'public' is not recognised by PHP 4.

Colin

[Back to original 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

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