You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I try to fetch data using WithData trait for converting Eloquent model to a data object, but it does not return default empty array on promoted param when its value is null.
Here is my code:
class ActionData extends Data
{
public function __construct(
public BasicDetail $basic_detail;
){}
}
class BasicDetail extends Data
{
public function __construct(
public array $action_upgradeReplacements = [];
public ?int $action_modifiedDv1Value,
){}
}
It works in php 8.0, but in php 8.1, it throws error: "Argument #1 ($action_upgradeReplacements) must be of type array, null given".
The wierd thing is when $action_modifiedDv1Value has default value like public ?int $action_modifiedDv1Value = 0, problem disappears.
I am sure why is that.
Can anyone help me with this please?
Thanks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I try to fetch data using
WithData
trait for converting Eloquent model to a data object, but it does not return default empty array on promoted param when its value is null.Here is my code:
It works in php 8.0, but in php 8.1, it throws error: "Argument #1 ($action_upgradeReplacements) must be of type array, null given".
The wierd thing is when
$action_modifiedDv1Value
has default value likepublic ?int $action_modifiedDv1Value = 0
, problem disappears.I am sure why is that.
Can anyone help me with this please?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions