php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65229 Fatal error using class Inheritance
Submitted: 2013-07-09 21:21 UTC Modified: 2013-07-10 03:21 UTC
From: odiel dot leon at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.17 OS: Ubuntu 12.04.1 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: odiel dot leon at gmail dot com
New email:
PHP Version: OS:

 

 [2013-07-09 21:21 UTC] odiel dot leon at gmail dot com
Description:
------------
PHP is generating a fatal error when a class that inherit from another is getting instantiated and these classes are defined after being instantiated. 

If the class does not inherit PHP run the code without errors.



Test script:
---------------
<?php

$a = new Aa();
$a->hi();


class Aa extends Bb
{

}

class Bb
{
    public function hi()
    {
        echo('hi Aa');
    }
}



Expected result:
----------------
hi Aa

Actual result:
--------------
PHP Fatal error:  Class 'Aa' not found in /home/www/test.php on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-09 23:28 UTC] cmbecker69 at gmx dot de
This is not a bug, as it is clearly documented on
<http://www.php.net/manual/en/language.oop5.inheritance.php>:

| Unless autoloading is used, then classes must be defined before 
| they are used. If a class extends another, then the parent 
| class must be declared before the child class structure. This 
| rule applies to classes that inherit other classes and interfaces.
 [2013-07-10 03:21 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2013-07-10 03:21 UTC] laruence@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

as cmbecker69 said
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC