Re: PHP4 vs PHP5 classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-07-29 at 22:26 -0700, Jim Lucas wrote:
> Chris wrote:
> >> Don't forget that in PHP5, the constructor named has changed.  In PHP4
> >> it called a method with the same name as the class.  But, in PHP5, it
> >> looks for __construct() instead.
> > 
> > If __construct doesn't exist then it falls back to the php4 way - makes
> > it backwards compatible :)
> > 
> 
> But, if people want to code to php5 standards and beyond, then I would 
> recommend always using the __construct() method to construct your class. 
>   Then make it work in php4.  Not the other way around.

It's unfortunate that PHP5 decided to throw a Strict Standards exception
when you include both style constructors. For instance, I'm certain at
one point the following was recommended:

<?php
class Foo
{
    function __construct()
    {
    }

    function Foo()
    {
        self::__construct();
    }
}
?>

This was perfectly compatible with PHP5 and gave precedence to the PHP5
constructor style. Somewhere along the line though PHP5 started
spouting:

    Strict Standards: Redefining already defined constructor

So I just completely removed the PHP5 style constructors from my code
and use the PHP4 style since then there are no exceptions. Mark my words
though... at some point PHP will start spewing an E_DEPRECATED for PHP4
style constructor *lol*.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux