1
0
mirror of https://github.com/php/php-src.git synced 2026-04-22 23:48:14 +02:00
Files
archived-php-src/Zend/tests/weakrefs/weakrefs_003.phpt
T
Nikita Popov 653e4ea1c5 Add flag to forbid dynamic property creation on internal classes
While performing resource -> object migrations, we're adding
defensive classes that are final, non-serializable and non-clonable
(unless they are, of course). This path adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES
flag, that also forbids the creation of dynamic properties on these objects.
This is a subset of #3931 and targeted at internal usage only
(though may be extended to userland at some point in the future).

It's already possible to achieve this (what the removed
WeakRef/WeakMap code does), but there's some caveats: First, this
simple approach is only possible if the class has no declared
properties, otherwise it's necessary to special-case those
properties. Second, it's easy to make it overly strict, e.g. by
forbidding isset($obj->prop) as well. And finally, it requires a
lot of boilerplate code for each class.

Closes GH-5572.
2020-06-24 11:52:36 +02:00

29 lines
612 B
PHP

--TEST--
WeakReference object handlers
--FILE--
<?php
$wr = WeakReference::create(new stdClass);
var_dump($wr->disallow);
var_dump(isset($wr->disallow));
unset($wr->disallow);
try {
$wr->disallow = "writes";
} catch (Error $ex) {
var_dump($ex->getMessage());
}
try {
$disallow = &$wr->disallowed;
} catch (Error $ex) {
var_dump($ex->getMessage());
}
?>
--EXPECTF--
Warning: Undefined property: WeakReference::$disallow in %s on line %d
NULL
bool(false)
string(55) "Cannot create dynamic property WeakReference::$disallow"
string(57) "Cannot create dynamic property WeakReference::$disallowed"