php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57754 Problems with inherited classes
Submitted: 2007-07-20 19:03 UTC Modified: 2013-02-26 14:11 UTC
From: owlmanatt at gmail dot com Assigned: pollita (profile)
Status: Closed Package: runkit (PECL)
PHP Version: 5.1.2 OS: Ubuntu Linux 6.06 LTS
Private report: No CVE-ID: None
 [2007-07-20 19:03 UTC] owlmanatt at gmail dot com
Description:
------------
Hi,

I'm having some trouble with runkit_import and runkit_class_adopt. I've tested this w/ PHP 5.1.2, Runkit 0.9 AND Runkit's CVS HEAD. The behaviours have been observed in both 0.9 and HEAD. I have attepted this all from the command line and from Apache2/mod_php5.

To summarize, I have two classes - Foo and FooParent. FooParent has one method, and Foo also has this method in it.

First, I tried Foo extends FooParent. I would use runkit_import for the initial load of the class file (instead of require/include), and it would load the class and behave as expected.

However, when the class is loaded with runkit_import for the second time, I get the following error:

Fatal error: Cannot redeclare class foo in /home/nevans/classkit/foo.class.php on line 23

This is how I am calling it:
runkit_import('foo.class.php',RUNKIT_IMPORT_CLASSES|RUNKIT_IMPORT_OVERRIDE);

If I take the extends FooParent out of the class definition, I am able to re-load the class as many times as I like without any fatal errors.

So, fine - I saw a potential workaround with runkit_class_adopt. I commented out the extends FooParent in Foo's class definition and tried to load it like this:

runkit_import('foo.class.php',RUNKIT_IMPORT_CLASSES|RUNKIT_IMPORT_OVERRIDE);
runkit_class_adopt('Foo','FooParent');

However, this causes a different problem. When runkit_adopt_class executes for the first time, I get this warning:

Warning: runkit_class_adopt(): Error inheriting parent method: sayDesu() in /home/nevans/classkit/test.php on line 18

Fatal error: Cannot access parent:: when current class scope has no parent in /home/nevans/classkit/foo.class.php on line 21

The fatal error implies that the class was not adopted by FooParent successfully.

Please see the link to my example code for further details.


Reproduce code:
---------------
Class definitions: http://owly.homelinux.net/~nevans/code/runkit/foo.class.phps

Test:
http://owly.homelinux.net/~nevans/code/runkit/test.phps


Expected result:
----------------
In the first case, using just runkit_import, I expect the class to be re-loaded successfully.

In the second case, using runkit_import and runkit_class_adopt, I expect runkit_class_adopt to properly load the parent's methods in and child the class to FooParent.

Actual result:
--------------
See the description.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-26 14:11 UTC] pollita@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
 [2013-02-26 14:11 UTC] pollita@php.net
The fix for this bug has been committed.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC