PHP 8.4.0RC4: Zend Observer does not work for PDO query() method when the new PDO connect() is used
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.1k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
Problem Description
We have a custom PHP extension that registers as an observer for PDO extension's methods like __construct(), query(), etc., and our extension's handler functions get invoked when any of these PDO methods are being executed. This code is pretty generic from our side and is the same for all PDO methods we observe. But starting from PHP 8.4.0, our observer functions/function handlers are not being invoked when PDO query() method is being executed (when connect() is used) - the execution directly goes to PDO query() method instead of our registered function handlers. There is some crucial, unexplained behavioral difference I want to highlight here considering PHP introduced connect() method to create PDO objects. We adapted our code to also register observer & function handler for the new connect() method and our function handler is being invoked correctly for connect() method but not for query() method that is executed after the connect().
So:
If PDO::__construct() is used by PHP app, our extension's function handlers for __construct() AND query() are both correctly invoked by the Zend engine.
If PDO::connect() is used by PHP app, only connect() function handler in our extension is invoked but not the function handler for query().
This is inconsistent behaviour from the Zend engine.
Just to clarify how we use Zend observer API:
During MINIT:
- We use
zend_observer_fcall_register()to register begin and end function handlers. - We use the
CG()macro to get class entry object for "PDO" class and overwrite thezend_function->internal_function_handlerwith our own function for__construct(), connect(), query()
We verified some aspects during runtime using a debugger :
- Looking into the CG hashtable after we register our functions - we can confirm that
zend_function->internal_function_handlerfor both connect() and query() hold the pointers to our extension's overwritten function handler, not the original PDO methods. 2. InsideZEND_DO_FCALL_SPEC_OBSERVER_HANDLER()inzend_vm_execute.hfrom where these two functions/PDO methods are eventually invoked, we can see that thefbc->internal_function.handlerfor duringquery()execution holds some unresolved address - that is neither pointing tozim_PDO_query()or our extension's overwritten function handler.
Strange thing is, for the PDO connect() execution, fbc->internal_function.handler does point to our extension's function handler. As I said, registering observer and overwriting function handlers for these functions in the CG hashtable is generic and has been working on PHP 8.3.
PHP Version
PHP 8.4.0RC4
Operating System
No response
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduzca la diferencia entre PDO::__construct() y PDO::connect() seguido de query() utilizando el registro del observer de Zend y las sobrescrituras del handler descritas en el issue. Comience en ZEND_DO_FCALL_SPEC_OBSERVER_HANDLER() en zend_vm_execute.h e inspeccione las entradas de PDO en la CG hashtable; la tarea estará terminada cuando query() invoque sistemáticamente el handler del observer registrado después de connect().
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, php
- Área
- backend, compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100