|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-01-19 11:24 UTC] arash at yalpani dot de
In the documentation (http://www.php.net/manual/en/language.oop.constructor.php) you defined the following rule: "If a class has no constructor, the constructor of the base class is being called, if it exists" This worked in PHP 4.0.6 for me. After upgrading to Version 4.1.1, it doesn't. Here are my test-scripts. The first one ends up with no output or the errormessage: "Fatal error: Cannot instantiate non-existent class: mountainbike in /www/testOO.php on line 15". actually, the behaviour seems to be undefined. The second one works, as it should be, but only because of actively calling the constructor of the base class. FIRST: <?php class Bike { function Bike() { echo 'Constructor of class "Bike"'; } } class MountainBike extends Bike { } $mb = new MountainBike(); ?> SECOND: <?php class Bike { function Bike() { echo 'Constructor of class "Bike"'; } } class MountainBike extends Bike { function MountainBike() { parent::Bike(); } } $mb = new MountainBike(); ?> Greetings, Arash My configure line is: ./configure \ --with-apxs=/usr/local/apache/1.3.20/bin/apxs \ --enable-track-vars \ --enable-ftp \ --with-zlib \ --with-gd \ --with-pdflib \ --with-sockets \ --enable-sockets \ --with-sysvshm \ --with-sysvsem \ --enable-dbg=shared \ --with-dbg-profiler \ --with-mysql=/usr/local/mysql/current \ --with-pgsql=/usr/local/pgsql \ --with-mcrypt PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 26 08:00:01 2025 UTC |
I was unable to reproduce this bug. The following code executes as expected for me (Win2k/Apache PHP 4.1.1): class Bike { function Bike() { echo 'Constructor of class "Bike"<br>'; } } class MountainBike extends Bike { } $mb = new MountainBike(); class Bike2 { function Bike2() { echo 'Constructor of class "Bike2"<br>'; } } class MountainBike2 extends Bike2 { function MountainBike2() { parent::Bike2(); } } $mb = new MountainBike2(); It outputs: Constructor of class "Bike" Constructor of class "Bike2" with no compile errors. Double check that you aren't including a wrong file, etc.