[php-maint] Bug#498914: Bug#498914: php5-cli: Class-named functions are treated as constructors, but only in included files

Raphael Geissert atomo64 at gmail.com
Sun Sep 14 19:21:54 UTC 2008

forwarded 498914 http://bugs.php.net/46077
tag 498914 upstream
severity 498914 minor

2008/9/14 Patrik Fimml <patrik at fimml.at>:
> Package: php5-cli
> Version: 5.2.6-3
> Severity: normal
> When defining a function with the same name as the enclosing class, it
> is treated as a constructor for backwards-compatibility. However, if
> there is a __construct() function, it should be ignored.

It actually is being ignored.

> PHP handles this correctly when the class is defined in a script file
> that is directly executed, but reports an error (two constructors) if
> the class comes from an included file.

The only difference is the missing warning (and probably some lines of
code not being exewcuted either).

Using a slightly modified version of your scripts:

$ cat a.php

error_reporting(E_ALL | E_STRICT);

class A
    function __construct() { echo "foo\n"; }
    function A() { echo "bar\n"; }
$a = new A();

$ cat test.php

error_reporting(E_ALL | E_STRICT);

$b= new A;


$ php -n a.php ; echo ---; php -n test.php; echo ---

Strict Standards: Redefining already defined constructor for class A
in /tmp/a.php on line 8

Atomo64 - Raphael

Please avoid sending me Word, PowerPoint or Excel attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

More information about the pkg-php-maint mailing list