Skip to content

Conversation

@Seb-C
Copy link
Contributor

@Seb-C Seb-C commented Nov 27, 2017

Hello,

I've encountered an error when saving multiple Searchable items from different models. It's related to type-hinting closures with the self keyword from a trait. While it's a bug in the PHP interpreter, it can cause critical errors in applications using the Searchable trait.

This PR is just a workaround for this error.

It's related to the bug declared here: https://bugs.php.net/bug.php?id=75079

And here is an example to reproduce it:

trait T {
    public static function test()
    {
        return function (self $x) {
            print_r($x);
        };
    }
}

class A {
    use T;
}

class B {
    use T;
}

$a = A::test();
$b = B::test();

$a(new A());
$b(new B());

Result:

B Object
(
)
Fatal error: Uncaught TypeError: Argument 1 passed to A::{closure}() must be an instance of B, instance of A given, called in [...][...] on line 24 and defined in...

@jamesgraham
Copy link
Contributor

This duplicates #124

Can we get this change merged @sleimanx2 ?

@sleimanx2 sleimanx2 merged commit 4248604 into sleimanx2:master Jan 22, 2018
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.

3 participants