The **const** modifier needs to be added to read-only parameters of all ZendAPI and PHPAPI functions
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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:
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the PHPAPI and ZEND_API declarations and implementations for fast_equal_check_function, php_debug_zval_dump, php_var_dump, php_var_unserialize, concat_function, add_function, is_equal_function, zval_get_string, and zval_get_double. Determine which zval parameters are not modified, then update the applicable signatures consistently across the affected functions and verify that the PHP source still builds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100