php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27227 Mixed case class names causes Fatal Error in Constructor call
Submitted: 2004-02-11 19:20 UTC Modified: 2004-03-16 10:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: waboring at 3gstech dot com Assigned: andi
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-02-11 OS: *
Private report: No CVE-ID:
 [2004-02-11 19:20 UTC] waboring at 3gstech dot com
Description:
------------
I have 3 classes a, b extends a, c extends b.

b doesn't have constructor.

c class contructor calls b's constructor in an effort
to cascade constructor calls up the class heirarchy.

This works great until class 'a' is renamed to 'A'.

<?php
/* This script works as one would expect.
  The foo class constructor gets called.
 */
class a {
    function a() {
        echo __CLASS__."::".__FUNCTION__." called!<br>\n";
    }
}

class b extends a {

    function blah() {
        echo __CLASS__."::".__FUNCTION__."() called<br>\n";
    }
}

class c extends b {
    function c() {
        echo __CLASS__."::".__FUNCTION__."() called!!<br>\n";
        $this->b();
    }
}

$obj = new c();
$obj->blah();

/* Output is
c::c() called!!
a::a called!
b::blah() called
*/
?>



Reproduce code:
---------------
<?php
/* 
  Notice that the only thing that is different here is the
  case of the 'a' class changed to 'A' in all the appropriate places.  Now I get a Fatal error saying
c::b() doesn't exist?

*/

class A {
    function A() {
        echo __CLASS__."::".__FUNCTION__." called!<br>\n";
    }
}

class b extends A {

    function blah() {
        echo __CLASS__."::".__FUNCTION__."() called<br>\n";
    }
}

class c extends b {
    function c() {
        echo __CLASS__."::".__FUNCTION__."() called!!<br>\n";
        $this->b();
        //ERROR IN LINE ABOVE
    }
}

$obj = new c();
$obj->blah();

/* Output is

c::c() called!!

Fatal error: Call to undefined method c::b() in /home/waboring/devel/php/oop.php on line 18

*/
?>

Expected result:
----------------
I expect that both of the scripts would work the same way.  I have many classes that have Mixed case 

Actual result:
--------------
Fatal error: Call to undefined method c::b() in /home/waboring/devel/php/oop.php on line 18



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-11 20:33 UTC] sniper@php.net
Works fine with PHP 4 btw. :) (somehow I think this might be one for Marcus to fix..?)


 [2004-02-15 19:28 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2004-02-19 13:17 UTC] waboring at 3gstech dot com
Actually this hasn't been completely fixed.  This is the same issue as the original post.  Please do not close this bug as it is NOT fixed.  This is the same issue.  The first third child class can't resolve the cascade of the constructor call back to the parent class just because the case and name of the classes change.

<?php
class A {
    function A() {
        echo __CLASS__."::".__FUNCTION__." called!<br>\n";
    }
}

class bTesting extends A {

    function blah() {
        echo __CLASS__."::".__FUNCTION__."() called<br>\n";
    }
}

class c extends bTesting {
    function c() {
        echo __CLASS__."::".__FUNCTION__."() called!!<br>\n";
        $this->bTesting();
    }
}

$obj = new c();
$obj->blah();
?>

results in:
c::c() called!!

Fatal error: Call to undefined method c::bTesting() in
/home/waboring/devel/bug.php on line 18
 [2004-02-20 04:37 UTC] sniper@php.net
Marcus, this fix wasn't quite enough.
 [2004-03-03 14:29 UTC] derick@php.net
Anything new on this?
 [2004-03-14 12:59 UTC] andi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please use parent::__construct() to call the parent's constructor. We don't support calling it via the object and definitely not using the depricated fashion of using the classes name as the constructor name.
 [2004-03-15 13:22 UTC] waboring at 3gstech dot com
This bug is far from bogus.  You say that this using the name of the class as a function is depricated for a constructor?  Deprecated and removed are two entirely different things.

If it's deprecated, it should be noted in the documentation that it's deprecated, but it should still work.  If what you mean by deprecated is removed, then it should be consistent and be removed entirely.  

If you name the class with no mixed case in the name, it works fine. Change the name of the parent class to have mixed case, and it doesn't work. It clearly points out how inconsistent php5 is.  If php5 doesn't support class name functions as the constructor, it should at least be consistent.
 [2004-03-15 13:43 UTC] sniper@php.net
assigning to Andi to give proper feedback.. :)

 [2004-03-16 10:14 UTC] andi@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 13:02:15 2014 UTC