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

Unbinding $this of closure is deprecated on php 7.4 #84

Closed
oleghalin opened this issue Oct 29, 2020 · 5 comments · Fixed by #85
Closed

Unbinding $this of closure is deprecated on php 7.4 #84

oleghalin opened this issue Oct 29, 2020 · 5 comments · Fixed by #85

Comments

@oleghalin
Copy link

The issue is related to that closure was unserialized first, then Closure was serialized again and it doesn't have this attribute. Is there a way to bind $this to newly serialized closure?

basically here is 2 Closures, which I try to serialize. I figured out that issue is related to "isBindingRequired" is false for a second.

image
image

@aliwesome
Copy link

I have same issue.

@e1himself
Copy link

Same issue. Had to rewrite the code without using $this.

@e1himself
Copy link

e1himself commented Nov 6, 2020

I've narrowed the root cause to the fact that isBindingRequired property is calculated during ReflectionClosure::getCode() parsing. But parsing is skipped altogether when you get a reflector for an unserialized SerializedClosure that already has non-null $this->code value:

/**
* Get the reflector for closure
*
* @return ReflectionClosure
*/
public function getReflector()
{
if ($this->reflector === null) {
$this->reflector = new ReflectionClosure($this->closure, $this->code);
$this->code = null;
}
return $this->reflector;
}

/**
* ReflectionClosure constructor.
* @param Closure $closure
* @param string|null $code
* @throws \ReflectionException
*/
public function __construct(Closure $closure, $code = null)
{
$this->code = $code;
parent::__construct($closure);
}

/**
* @return string
*/
public function getCode()
{
if($this->code !== null){
return $this->code;
}
$fileName = $this->getFileName();
$line = $this->getStartLine() - 1;
$match = ClosureStream::STREAM_PROTO . '://';

@oleghalin
Copy link
Author

Yeah, i saw it too. It will be serialized, but $this will not be attach as scope to new serialized closure.

@e1himself
Copy link

Thanks a lot @msarca! 🎉

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 a pull request may close this issue.

3 participants