Closed
Description
Description
Hello, I think I found some bugs here.
- take official docker image
- install opcache
- set opcache.ini config as:
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=100M
opcache.jit=1205
The following code:
<?php
declare(strict_types=1);
interface EntityManagerInterface {
public function persist(object $entity);
}
class EntityManager implements EntityManagerInterface {
public function persist(object $entity)
{
echo "Persisting entity: " . get_class($entity) . "\n";
}
}
abstract class AbstractDecorator implements EntityManagerInterface {
protected $wrapped;
public function persist(object $entity)
{
$this->wrapped->persist($entity);
}
}
class EntityManagerDecorator extends AbstractDecorator {
protected object $proxy;
protected $wrapped {
get {
if (!isset($this->proxy)) {
$this->proxy = ($this->factory)();
}
return $this->proxy;
}
}
public function __construct(private Closure $factory)
{
}
}
$em = new EntityManagerDecorator(static fn() => new EntityManager());
$a = new stdClass();
$em->persist($a);
$a1 = new stdClass();
$em->persist($a1);
Case 1: SEGMENTATION FAULT
If run this code, then it will be crash on
$em->persist($a1);
Case 2: Fatal error (unexpected behaviour)
If remove in this code interface EntityManagerInterface and implements statements then it will be give fatal error:
Fatal error: Uncaught Error: Call to a member function persist() on null in /app/test.php:20
Stack trace:
#0 /app/test.php(42): AbstractDecorator->persist(Object(stdClass))
#1 {main}
thrown in /app/test.php on line 20
If disable opcache or use tracing mode it will be work as expected:
Persisting entity: stdClass
Persisting entity: stdClass
P.S. I tried test PHP 8.4.3RC1 - bugs also exists there.
PHP Version
PHP 8.4.2
Operating System
Alpine 3.21