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-- Reflection Bug #81611 (ArgumentCountError when getting default value from Reflect..

Decoded Output download

--TEST--
Reflection Bug #81611 (ArgumentCountError when getting default value from ReflectionParameter with new)
--FILE--
<?php

class Bar
{
}

class Foo extends Bar
{
    public function doFoo(object $test = new self()): object
    {
        return $test;
    }

    public function doBar(object $test = new parent()): object
    {
        return $test;
    }
}

$ref = new \ReflectionClass(Foo::class);

foreach (['doFoo', 'doBar'] as $method) {
    $params = $ref->getMethod($method)->getParameters();

    foreach ($params as $param) {
        echo "isDefaultValueAvailable:
";
        var_dump($param->isDefaultValueAvailable());

        echo "isDefaultValueConstant:
";
        var_dump($param->isDefaultValueConstant());

        echo "getDefaultValueConstantName:
";
        var_dump($param->getDefaultValueConstantName());

        echo "getDefaultValue:
";
        var_dump($param->getDefaultValue());

        echo "
";
    }
}
?>
--EXPECT--
isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Foo)#2 (0) {
}

isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Bar)#3 (0) {
}

Did this file decode correctly?

Original Code

--TEST--
Reflection Bug #81611 (ArgumentCountError when getting default value from ReflectionParameter with new)
--FILE--
<?php

class Bar
{
}

class Foo extends Bar
{
    public function doFoo(object $test = new self()): object
    {
        return $test;
    }

    public function doBar(object $test = new parent()): object
    {
        return $test;
    }
}

$ref = new \ReflectionClass(Foo::class);

foreach (['doFoo', 'doBar'] as $method) {
    $params = $ref->getMethod($method)->getParameters();

    foreach ($params as $param) {
        echo "isDefaultValueAvailable:\n";
        var_dump($param->isDefaultValueAvailable());

        echo "isDefaultValueConstant:\n";
        var_dump($param->isDefaultValueConstant());

        echo "getDefaultValueConstantName:\n";
        var_dump($param->getDefaultValueConstantName());

        echo "getDefaultValue:\n";
        var_dump($param->getDefaultValue());

        echo "\n";
    }
}
?>
--EXPECT--
isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Foo)#2 (0) {
}

isDefaultValueAvailable:
bool(true)
isDefaultValueConstant:
bool(false)
getDefaultValueConstantName:
NULL
getDefaultValue:
object(Bar)#3 (0) {
}

Function Calls

None

Variables

None

Stats

MD5 6255f15d525ad577e8c6f904a6cc895b
Eval Count 0
Decode Time 84 ms