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-- Coalesce assign (??=): ArrayAccess handling --FILE-- <?php function id($arg) { ..

Decoded Output download

--TEST--
Coalesce assign (??=): ArrayAccess handling
--FILE--
<?php

function id($arg) {
    echo "id($arg)
";
    return $arg;
}

class AA implements ArrayAccess {
    public $data;
    public function __construct($data = []) {
        $this->data = $data;
    }
    public function &offsetGet($k): mixed {
        echo "offsetGet($k)
";
        return $this->data[$k];
    }
    public function offsetExists($k): bool {
        echo "offsetExists($k)
";
        return array_key_exists($k, $this->data);
    }
    public function offsetSet($k,$v): void {
        echo "offsetSet($k,$v)
";
        $this->data[$k] = $v;
    }
    public function offsetUnset($k): void { }
}

$ary = new AA(["foo" => new AA, "null" => null]);

echo "[foo]
";
$ary["foo"] ??= "bar";

echo "[bar]
";
$ary["bar"] ??= "foo";

echo "[null]
";
$ary["null"] ??= "baz";

echo "[foo][bar]
";
$ary["foo"]["bar"] ??= "abc";

echo "[foo][bar]
";
$ary["foo"]["bar"] ??= "def";

?>
--EXPECT--
[foo]
offsetExists(foo)
offsetGet(foo)
[bar]
offsetExists(bar)
offsetSet(bar,foo)
[null]
offsetExists(null)
offsetGet(null)
offsetSet(null,baz)
[foo][bar]
offsetExists(foo)
offsetGet(foo)
offsetExists(bar)
offsetGet(foo)
offsetSet(bar,abc)
[foo][bar]
offsetExists(foo)
offsetGet(foo)
offsetExists(bar)
offsetGet(bar)

Did this file decode correctly?

Original Code

--TEST--
Coalesce assign (??=): ArrayAccess handling
--FILE--
<?php

function id($arg) {
    echo "id($arg)\n";
    return $arg;
}

class AA implements ArrayAccess {
    public $data;
    public function __construct($data = []) {
        $this->data = $data;
    }
    public function &offsetGet($k): mixed {
        echo "offsetGet($k)\n";
        return $this->data[$k];
    }
    public function offsetExists($k): bool {
        echo "offsetExists($k)\n";
        return array_key_exists($k, $this->data);
    }
    public function offsetSet($k,$v): void {
        echo "offsetSet($k,$v)\n";
        $this->data[$k] = $v;
    }
    public function offsetUnset($k): void { }
}

$ary = new AA(["foo" => new AA, "null" => null]);

echo "[foo]\n";
$ary["foo"] ??= "bar";

echo "[bar]\n";
$ary["bar"] ??= "foo";

echo "[null]\n";
$ary["null"] ??= "baz";

echo "[foo][bar]\n";
$ary["foo"]["bar"] ??= "abc";

echo "[foo][bar]\n";
$ary["foo"]["bar"] ??= "def";

?>
--EXPECT--
[foo]
offsetExists(foo)
offsetGet(foo)
[bar]
offsetExists(bar)
offsetSet(bar,foo)
[null]
offsetExists(null)
offsetGet(null)
offsetSet(null,baz)
[foo][bar]
offsetExists(foo)
offsetGet(foo)
offsetExists(bar)
offsetGet(foo)
offsetSet(bar,abc)
[foo][bar]
offsetExists(foo)
offsetGet(foo)
offsetExists(bar)
offsetGet(bar)

Function Calls

None

Variables

None

Stats

MD5 3a88130a8c7922daf86827741cbc7936
Eval Count 0
Decode Time 115 ms