Skip to content

Commit 2cd8870

Browse files
committed
As create_object handler is copied from the parent class, we should ignore situations when we are trying to
extend a class that already has necessary create_object handler installed by Z-engine. Only internal classes should be ignored as we can't allocate memory for them and to perform initialization
1 parent ff86e7f commit 2cd8870

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Core.php

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class Core
182182
public const ZEND_USER_FUNCTION = 2;
183183
public const ZEND_EVAL_CODE = 4;
184184

185+
public const ZEND_INTERNAL_CLASS = 1;
186+
public const ZEND_USER_CLASS = 2;
187+
185188
/**
186189
* User opcode handler return values
187190
*/

src/Reflection/ReflectionClass.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ public function addMethod(string $methodName, \Closure $method): ReflectionMetho
314314
return $refMethod;
315315
}
316316

317+
public function isInternal()
318+
{
319+
return ord($this->pointer->type) === Core::ZEND_INTERNAL_CLASS;
320+
}
321+
322+
public function isUserDefined()
323+
{
324+
return ord($this->pointer->type) === Core::ZEND_USER_CLASS;
325+
}
326+
317327
/**
318328
* Removes given methods from the class
319329
*
@@ -830,8 +840,8 @@ public function setDoOperationHandler(Closure $handler): void
830840
public function setCreateObjectHandler(Closure $handler): void
831841
{
832842
// User handlers are only allowed with std_object_handler (when create_object handler is empty)
833-
if ($this->pointer->create_object !== null) {
834-
throw new \LogicException("Create object handler is available for user-defined classes only");
843+
if ($this->isInternal()) {
844+
trigger_error("Create object handler is available for user-defined classes only", E_USER_ERROR);
835845
}
836846
self::allocateClassObjectHandlers($this->getName());
837847

0 commit comments

Comments
 (0)