Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
--TEST-- ReflectionProperty::getValue() on typed static property --FILE-- <?php class Tes..
Decoded Output download
--TEST--
ReflectionProperty::getValue() on typed static property
--FILE--
<?php
class Test {
public static int $x = 42;
public static int $y;
public static $z;
}
$rp = new ReflectionProperty('Test', 'x');
var_dump($rp->getValue());
$rp = new ReflectionProperty('Test', 'y');
try {
var_dump($rp->getValue());
} catch (Error $e) {
echo $e->getMessage(), "
";
}
$rp->setValue("24");
var_dump($rp->getValue());
try {
$rp->setValue("foo");
} catch (TypeError $e) {
echo $e->getMessage(), "
";
}
var_dump($rp->getValue());
Test::$z =& Test::$y;
$rp = new ReflectionProperty('Test', 'z');
try {
$rp->setValue("foo");
} catch (TypeError $e) {
echo $e->getMessage(), "
";
}
var_dump($rp->getValue());
?>
--EXPECT--
int(42)
Typed static property Test::$y must not be accessed before initialization
int(24)
Cannot assign string to property Test::$y of type int
int(24)
Cannot assign string to reference held by property Test::$y of type int
int(24)
Did this file decode correctly?
Original Code
--TEST--
ReflectionProperty::getValue() on typed static property
--FILE--
<?php
class Test {
public static int $x = 42;
public static int $y;
public static $z;
}
$rp = new ReflectionProperty('Test', 'x');
var_dump($rp->getValue());
$rp = new ReflectionProperty('Test', 'y');
try {
var_dump($rp->getValue());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$rp->setValue("24");
var_dump($rp->getValue());
try {
$rp->setValue("foo");
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
var_dump($rp->getValue());
Test::$z =& Test::$y;
$rp = new ReflectionProperty('Test', 'z');
try {
$rp->setValue("foo");
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
var_dump($rp->getValue());
?>
--EXPECT--
int(42)
Typed static property Test::$y must not be accessed before initialization
int(24)
Cannot assign string to property Test::$y of type int
int(24)
Cannot assign string to reference held by property Test::$y of type int
int(24)
Function Calls
None |
Stats
MD5 | 83432a2a759f5eed0a7ea97c57cb53f8 |
Eval Count | 0 |
Decode Time | 77 ms |