framework icon indicating copy to clipboard operation
framework copied to clipboard

Specific `InputBag` behavior

Open roquie opened this issue 2 years ago • 0 comments

<?php

use Ramsey\Uuid\Uuid;

require __DIR__ . '/vendor/autoload.php';

$inputBag = new \Spiral\Http\Request\InputBag([
    'test' => null
]);

$arrayObject = new \ArrayObject([
    'test' => null
]);

var_dump('$inputBag', isset($inputBag['test']));
var_dump('$arrayObject', isset($arrayObject['test']));

$propertyInputBag = isset($inputBag['test']) && $inputBag['test'] !== null ? Uuid::fromString($inputBag['test']) : null;
$propertyArrayObject = isset($arrayObject['test']) ? Uuid::fromString($arrayObject['test']) : null;

// isset() PHP documentation:
// * <p>Determine if a variable is set and is not <b>NULL</b>.</p>

// Unexpected behavior.

Result:

string(9) "$inputBag"
bool(true)
string(12) "$arrayObject"
bool(false)
  • $propertyInputBag using long form and may confuse developer...

It's normal behavior or it a bug?

roquie avatar May 27 '22 18:05 roquie