Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Lost resource. #930

Open
fridreman opened this issue Feb 26, 2019 · 0 comments
Open

Lost resource. #930

fridreman opened this issue Feb 26, 2019 · 0 comments

Comments

@fridreman
Copy link

Environment

  • PHP: 7.2.2
  • pthreads: 3.2.1dev

Summary

When assigning another object in the class constructor, the resource is lost.

Reproducing Code

$customSocket = new CustomSocket();
$exampleThread = new ExampleThread($customSocket);

class CustomSocket {
    public $socket;

    public function __construct()
    {
        $this->socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
    }
}

class ExampleThread extends Thread {
    public $localCustomSocket;
    public $localSocket;

    public function __construct(CustomSocket $customSocket)
    {
        var_dump($customSocket);

        $this->localCustomSocket = $customSocket;
        var_dump($this->localCustomSocket);

        $constructorCustomSocket = $customSocket;
        var_dump($constructorCustomSocket);

        $this->localSocket = $customSocket->socket;
        var_dump($this->localSocket);
    }
}

Expected Output

object(CustomSocket)#1 (1) {
  ["socket"]=>
  resource(5) of type (Socket)
}
object(CustomSocket)#3 (1) {
  ["socket"]=>
  resource(5) of type (Socket)
}
object(CustomSocket)#1 (1) {
  ["socket"]=>
  resource(5) of type (Socket)
}
resource(5) of type (Socket)

Actual Output

object(CustomSocket)#1 (1) {
  ["socket"]=>
  resource(5) of type (Socket)
}
object(CustomSocket)#3 (1) {
  ["socket"]=>
  int(0)
}
object(CustomSocket)#1 (1) {
  ["socket"]=>
  resource(5) of type (Socket)
}
resource(5) of type (Socket)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant