Skip to content

[9.x] Remove null default attributes names when UPDATED_AT or CREATED_AT is null at Model::replicate#43279

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
mazinsw:9.x
Jul 19, 2022
Merged

[9.x] Remove null default attributes names when UPDATED_AT or CREATED_AT is null at Model::replicate#43279
taylorotwell merged 2 commits into
laravel:9.xfrom
mazinsw:9.x

Conversation

@mazinsw

@mazinsw mazinsw commented Jul 19, 2022

Copy link
Copy Markdown
Contributor

$this->getUpdatedAtColumn(),

Generates on PHP 8.0
PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated

Example:

class Order extends Model
{
    public const CREATED_AT = 'created_at';
    public const UPDATED_AT = null;

Code at database Model:

    public function replicate(array $except = null)
    {
        $defaults = [
            $this->getKeyName(),
            $this->getCreatedAtColumn(),
            $this->getUpdatedAtColumn(), // <---- null here
        ];

        $attributes = Arr::except( // <-- call Arr::forget
            $this->getAttributes(), $except ? array_unique(array_merge($except, $defaults)) : $defaults
        );

Trigger warning at Arr::forget:

public static function forget(&$array, $keys)
    {
        ...
        foreach ($keys as $key) {
            ...
            $parts = explode('.', $key); // <-- $key is null where but explode requires strict string type (null not allowed)

@mazinsw mazinsw changed the title fix: Model::replicate default attributes with null names when UPDATED_AT or CREATED_AT is null [9.x] fix: Model::replicate default attributes with null names when UPDATED_AT or CREATED_AT is null Jul 19, 2022
@mazinsw mazinsw changed the title [9.x] fix: Model::replicate default attributes with null names when UPDATED_AT or CREATED_AT is null [9.x] Remove null default attributes names when UPDATED_AT or CREATED_AT is null at Model::replicate Jul 19, 2022
@taylorotwell taylorotwell merged commit 067c218 into laravel:9.x Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants