From:
Operating system:
PHP version: 5.4.1RC2
Package: Scripting Engine problem
Bug Type: Bug
Bug description:__clone/__destruct do not match other methods when checking
access controls
Description:
------------
__clone and __destruct check access to protected methods differently from
other
methods. They have
custom implementation and while other methods allow access to siblings in
the
same tree to protected
functions, those do not. See implementation for regular ones:
if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc),
EG(scope)))) {
if (zobj->ce->__call) {
fbc = zend_get_user_call_function(zobj->ce, method_name,
method_len);
} else {
zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from
context '%s'",
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc),
method_name, EG(scope) ?
EG(scope)->name : "");
}
}
and for __clone:
if (UNEXPECTED(!zend_check_protected(clone->common.scope, EG(scope)))) {
zend_error_noreturn(E_ERROR, "Call to protected %s::__clone() from
context '%s'", ce->name,
EG(scope) ? EG(scope)->name : "");
}
it can be seen that __clone does not use zend_get_function_root_class().
Same
happens for destructor.
I see no reason for that and I think they should be brought in sync with
the
rest of the code. See also:
http://www.mail-archive.com/[email protected]/msg57424.html
Test script:
---------------
abstract class BaseClass {
abstract protected function __clone();
}
class MommasBoy extends BaseClass {
protected function __clone() {
echo __METHOD__, "\n";
}
}
class LatchkeyKid extends BaseClass {
public function __construct() {
echo 'In ', __CLASS__, ":\n";
$kid = new MommasBoy();
$kid = clone $kid;
}
public function __clone() {}
}
$obj = new LatchkeyKid();
Expected result:
----------------
In LatchkeyKid:
MommasBoy::__clone
Actual result:
--------------
Fatal error: Call to protected MommasBoy::__clone() from context
'LatchkeyKid' in
bug.php on line 16
--
Edit bug report at https://bugs.php.net/bug.php?id=61782&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=61782&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=61782&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=61782&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=61782&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=61782&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=61782&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=61782&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=61782&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=61782&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=61782&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=61782&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=61782&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=61782&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=61782&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=61782&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61782&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=61782&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=61782&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=61782&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=61782&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=61782&r=mysqlcfg