Bug #65229 [Com]: Fatal error using class Inheritance
| From: | cmbecker69 at gmx dot de | Date: | Tue, 09 Jul 2013 23:28:46 +0000 |
| Subject: | Bug #65229 [Com]: Fatal error using class Inheritance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180166@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65229&edit=1
ID: 65229
Comment by: cmbecker69 at gmx dot de
Reported by: odiel dot leon at gmail dot com
Summary: Fatal error using class Inheritance
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Ubuntu 12.04.1 LTS
PHP Version: 5.4.17
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-07-09 21:21:55] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65229&edit=1