[php-src] Issue #19523: The **const** modifier needs to be added to read-only parameters of all ZendAPI and PHPAPI functions
| From: | matyhtf | Date: | Wed, 20 Aug 2025 02:57:13 +0000 |
| Subject: | [php-src] Issue #19523: The **const** modifier needs to be added to read-only parameters of all ZendAPI and PHPAPI functions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250580@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/19523
Author: matyhtf
### Description
Many functions in the php source code receive the zval parameter. The value of the parameter is not
modified in the function implementation. These parameters are read-only, but the const modifier is
not added.
As a result, C/C++underlying developers do not know whether the function is a read-only operation or
a write operation, and will pollute all downstream functions. If these
PHPAPI or
ZEND_API functions are used in a C++function, even if the function is designed to be
read-only, the const modifier cannot be used, or only unsafe const_cast can be used to cast.
## An example:
```cpp
class Variant {
protected:
zval val;
void destroy() {
zval_ptr_dtor(&val);
}
public:
Variant(const zval *v) noexcept {
ZVAL_COPY_VALUE(&val, v);
}
const zval *const_ptr() const {
return &val;
}
// fast_equal_check_function should be fast_equal_check_function(const zval *op1, const
zval *op2)
bool equals(const Variant &v) const {
return fast_equal_check_function(const_ptr(), v.const_ptr());
}
}
```
## Problem function:
- fast_equal_check_function
- php_debug_zval_dump
- php_var_dump
- php_var_unserialize
- concat_function
- add_function
- is_equal_function
- zval_get_string
- zval_get_double // version 8.1
... a lot more functions