Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 19, 2022

Conversation

mazinsw
Copy link
Contributor

@mazinsw mazinsw commented Jul 19, 2022

$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