mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
In zend_std_has_property with ZEND_PROPERTY_EXISTS, we'd just return true when no get hook was present. However, this function is supposed to return false for uninitialized properties. PROPERTY_EXISTS is somewhat of a misnomer. Virtual properties continue to always return true, given there's no backing value to check. Fixes GH-15694 Closes GH-15822
57 lines
1012 B
PHP
57 lines
1012 B
PHP
--TEST--
|
|
ReflectionProperty::isInitialized() on hooked properties
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test {
|
|
// Plain
|
|
public $p1;
|
|
public string $p2;
|
|
// Virtual
|
|
public $v1 { get => throw new Exception(); }
|
|
public $v2 { set { throw new Exception(); } }
|
|
// Backed
|
|
public $b1 { get => throw new Exception($this->b1); }
|
|
public string $b2 { get => throw new Exception($this->b2); }
|
|
public $b3 { set => throw new Exception(); }
|
|
public string $b4 { set => throw new Exception(); }
|
|
}
|
|
|
|
$test = new Test();
|
|
$rc = new ReflectionClass(Test::class);
|
|
foreach ($rc->getProperties() as $rp) {
|
|
echo $rp->getName(), "\n";
|
|
var_dump($rp->isInitialized($test));
|
|
try {
|
|
$rp->setRawValue($test, 42);
|
|
} catch (Error $e) {}
|
|
var_dump($rp->isInitialized($test));
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
p1
|
|
bool(true)
|
|
bool(true)
|
|
p2
|
|
bool(false)
|
|
bool(true)
|
|
v1
|
|
bool(true)
|
|
bool(true)
|
|
v2
|
|
bool(true)
|
|
bool(true)
|
|
b1
|
|
bool(true)
|
|
bool(true)
|
|
b2
|
|
bool(false)
|
|
bool(true)
|
|
b3
|
|
bool(true)
|
|
bool(true)
|
|
b4
|
|
bool(false)
|
|
bool(true)
|