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-- Using settype() on a typed property --FILE-- <?php class Test { public int $..

Decoded Output download

--TEST--
Using settype() on a typed property
--FILE--
<?php

class Test {
    public int $x;
}

$test = new Test;
$test->x = 42;
settype($test->x, 'string');
// Same as $test->x = (string) $test->x.
// Leaves value unchanged due to coercion
var_dump($test->x);

try {
    settype($test->x, 'array');
} catch (TypeError $e) {
    echo $e->getMessage(), "
";
}
var_dump($test->x);

?>
--EXPECT--
int(42)
Cannot assign array to reference held by property Test::$x of type int
int(42)

Did this file decode correctly?

Original Code

--TEST--
Using settype() on a typed property
--FILE--
<?php

class Test {
    public int $x;
}

$test = new Test;
$test->x = 42;
settype($test->x, 'string');
// Same as $test->x = (string) $test->x.
// Leaves value unchanged due to coercion
var_dump($test->x);

try {
    settype($test->x, 'array');
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
var_dump($test->x);

?>
--EXPECT--
int(42)
Cannot assign array to reference held by property Test::$x of type int
int(42)

Function Calls

None

Variables

None

Stats

MD5 3bec57677b32a0dbd2c46342bb085221
Eval Count 0
Decode Time 85 ms