Skip to content

Commit

Permalink
update Resource.php
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 14, 2023
1 parent 42dd9e4 commit 5c33b5c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions zend/Types/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ class Resource extends \ZE

public function __destruct()
{
$this->extra = null;
if (!\is_null($this->extra)) {
$object = $this->extra;
$this->extra = null;
\zval_del_ref($object);
}

$this->free();
}

public function update(CData $ptr, bool $isOther = false): self
{
if ($isOther) {
\FFI::free($this->ze_other_ptr);
$this->ze_other_ptr = null;
$this->ze_other = null;
}

Expand All @@ -157,7 +163,7 @@ public function update(CData $ptr, bool $isOther = false): self

public function free(): void
{
if (!\is_null($this->ze_other_ptr) && \count($this->fd) === 0) {
if (!\is_null($this->ze_other_ptr)) {
if (\is_typeof($this->ze_other_ptr, 'struct _php_stream*'))
\ze_ffi()->_php_stream_free($this->ze_other_ptr, self::PHP_STREAM_FREE_CLOSE);
else
Expand Down Expand Up @@ -209,11 +215,15 @@ public function add_pair(Zval $zval, int $fd1, int $resource1, int $fd0 = null,
{
$this->zval = $zval;
$this->index = $fd1;
$this->fd[$fd1] = $this->fd[$resource1] = [$fd1, $resource1];
static::$instances[$fd1] = static::$instances[$resource1] = $this;
$this->fd[$fd1] = [$fd1, $resource1];
$this->fd[$resource1] = [$fd1, $resource1];
static::$instances[$fd1] = $this;
static::$instances[$resource1] = $this;
if (!\is_null($fd0) && !\is_null($resource0)) {
$this->fd[$fd0] = $this->fd[$resource0] = [$fd0, $resource0];
static::$instances[$fd0] = static::$instances[$resource0] = $this;
$this->fd[$fd0] = [$fd0, $resource0];
$this->fd[$resource0] = [$fd0, $resource0];
static::$instances[$fd0] = $this;
static::$instances[$resource0] = $this;
}

return $this;
Expand Down

0 comments on commit 5c33b5c

Please sign in to comment.