The **const** modifier needs to be added to read-only parameters of all ZendAPI and PHPAPI functions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die PHPAPI- und ZEND_API-Deklarationen und -Implementierungen für fast_equal_check_function, php_debug_zval_dump, php_var_dump, php_var_unserialize, concat_function, add_function, is_equal_function, zval_get_string und zval_get_double zu finden. Bestimme, welche zval-Parameter nicht verändert werden, aktualisiere anschließend die zutreffenden Signaturen in allen betroffenen Funktionen konsistent und überprüfe, dass der PHP-Quellcode weiterhin kompiliert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c
- Bereich
- compilers
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100