|
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
Navigation:
[Reply to this message]
|