php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57730 cannot declare methods in class that extends class from another file
Submitted: 2007-07-03 08:09 UTC Modified: 2009-11-23 13:24 UTC
From: bugotech at gmail dot com Assigned:
Status: Not a bug Package: bcompiler (PECL)
PHP Version: 5.2.1 OS: WinXP and Linux
Private report: No CVE-ID: None
 [2007-07-03 08:09 UTC] bugotech at gmail dot com
Description:
------------
If you declare class A with a method in one file and you declare class as extending class A, you cannot declare the method of class A in class B.

Reproduce code:
---------------
File a.php:

<?
class A
{
  public function Test()
  {
    echo("Test to class A");
  }
}
?>

File b.php:

<?
class B extends A
{
  public function WriteIn()
  {
    $this->Test();
  }
}
?>


File c.php:
<?
bcompiler_load('./a.obj');
bcompiler_load('./b.obj'); // Here this the erro

$obj = new B();
$obj->Test();
$obj->WriteIn();
?>

Expected result:
----------------
That it functions

Actual result:
--------------
unable inherit class B 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-16 06:11 UTC] zobo at scene-si dot org
Thats a tough one...
Simple solution, use "include" instead of bcompiler_load.
The problem is the "late binding" syndrome. When b.php is compiled, two instructions are inserted into the "main" function:

line     #  op                           fetch          ext  operands
-------------------------------------------------------------------------------
   3     0  ZEND_FETCH_CLASS                                 :0, 'CLASSA'
         1  ZEND_DECLARE_INHERITED_CLASS                     null, '%00classb%2Froot%2Fzobo%2Fbcompiler%2Ftests%2F11510%2Fb.php0x865502a', 'classb'


This brings out another problem.
most bcompiler loading functions (bcompiler_load, bcompiler_load_exe...) do not evaluate the returning op_array. So no late inheriting (bad). 
The problem is not so severe until you compile more files that have late binging classes to one binary file.
Then the "main" functions of each file overlaps and only the last gets executed.
 [2009-11-23 13:24 UTC] val@php.net
Thank you for taking the time to write to us, but this is not
a bug.

Please use include() instead of bcompiler_load(), it's the preferred way now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC