php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58521 runkit_class_adopt doesn't work as expected
Submitted: 2009-01-27 04:57 UTC Modified: 2013-02-23 18:33 UTC
From: luka8088 at gmail dot com Assigned: pollita (profile)
Status: Closed Package: runkit (PECL)
PHP Version: 5.2.5 OS: Windows
Private report: No CVE-ID: None
 [2009-01-27 04:57 UTC] luka8088 at gmail dot com
Description:
------------
I think this should work without errors.... And that would make runkit very useful for dynamic inheritance ... This is an example how to use one universal sql object that would load proper sql driver dynamically ... 


Reproduce code:
---------------
<?php 

class sql_mysql {
  function connect () {
    $this->link = 'Mysql Link';
    }
}

class sql_oracle {
  function connect () {
    $this->link = 'Oracle Link';
  }
}

class sql {

  function open ($driver, $connect_string) {
    runkit_class_adopt('sql', "sql_$driver");
    $this->connect($connect_string);
  }

  function close () {
    runkit_class_emancipate('sql');
  }

  }

$sql = new sql();
$sql->open('mysql', '...');
echo $sql->link . "\n";
var_dump(get_parent_class($sql));

$sql->close();

$sql->open('oracle', '...');
echo $sql->link . "\n";
var_dump(get_parent_class($sql));

?>

Expected result:
----------------
Output:
Mysql Link
string(9) "sql_mysql"
Oracle Link
string(10) "sql_oracle"

Actual result:
--------------
Output:
Mysql Link
bool(false)
Error: Class sql has no parent to emancipate from ...
Mysql Link
bool(false)

It seams that runkit just copies class methods, and does not actually extend the class, and becouse of that it cannot emancipate and again adopt it dynamically ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-23 18:33 UTC] pollita@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
 [2013-02-23 18:33 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.

https://github.com/php/pecl-php-
runkit/commit/6c0de2d859a16aa67382f8411a5f58e774467024
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 12:03:34 2022 UTC