php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #28459 Documentation and Object/class problem
Submitted: 2004-05-20 20:04 UTC Modified: 2005-04-26 16:51 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: alpzrjvr at hotmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.8 OS: Slackware 9.0, Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alpzrjvr at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-05-20 20:04 UTC] alpzrjvr at hotmail dot com
Description:
------------
http://cr2.php.net/language.oop.constructor

PHP manual says: 
In PHP 3, the function B() in class A will suddenly become a constructor in class B, although it was never intended to be. The rule in PHP 3 is: 'A constructor is a function of the same name as the class.'. PHP 3 does not care if the function is being defined in class B, or if it has been inherited. 

This is fixed in PHP 4 by modifying the rule to: 'A constructor is a function of the same name as the class it is being defined in.'. Thus in PHP 4, the class B would have no constructor function of its own and the constructor of the base class would have been called, printing 'I am the constructor of A.<br />'.


But, I test the script in diferent PHP's versions and the result was: 

"I am a regular function named B in class A.
I am not a constructor in A." ... with PHP 4.x.x .

Reproduce code:
---------------
<?
class A
{
   function A()
   {
       echo "I am the constructor of A.<br />\n";
   }

   function B()
   {
       echo "I am a regular function named B in class A.<br />\n";
       echo "I am not a constructor in A.<br />\n";
   }
}

class B extends A
{
   function C()
   {
       echo "I am a regular function.<br />\n";
   }
}

$b = new B();
or 
$b = new B; (also works)
?>

Expected result:
----------------
I am the constructor of A.

Actual result:
--------------
I am a regular function named B in class A.
I am not a constructor in A.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-26 16:51 UTC] vrana@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Dup of bug #22253.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 02 14:01:32 2024 UTC