-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric parent hook call fails with assertion #17234
Comments
Either we disallow this by checking the type, or we allow this by doing the following: diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 456c0b8f410..70db11c4cc2 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5098,7 +5098,8 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast,
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for parent property hook call");
}
- zend_string *property_name = zend_ast_get_str(class_ast->child[1]);
+ zval *property_hook_name_zv = zend_ast_get_zval(class_ast->child[1]);
+ zend_string *property_name = zval_get_string(property_hook_name_zv);
zend_string *hook_name = zend_ast_get_str(method_ast);
zend_property_hook_kind hook_kind = zend_get_property_hook_kind_from_name(hook_name);
ZEND_ASSERT(hook_kind != (uint32_t)-1);
@@ -5122,7 +5123,6 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast,
zend_op *opline = get_next_op();
opline->opcode = ZEND_INIT_PARENT_PROPERTY_HOOK_CALL;
opline->op1_type = IS_CONST;
- zend_string_copy(property_name);
opline->op1.constant = zend_add_literal_string(&property_name);
opline->op2.num = hook_kind;
However, this isn't really super useful as you can't define property hooks where the property name is numeric. |
I think it makes sense to fail at compile time when the property name is not a string. |
Okay, I'll get to that, thanks for the input |
@nielsdos Or probably just fall back to the normal behavior in the big ugly |
This is simple to do, but if you do this, then it becomes kind of inconsistent in meaning. <?php
class ParentC {}
class Child extends ParentC {
function a () { PARENT :: $ { 0} :: get () ; }
}; |
@nielsdos Right. We're sharing this syntax, and decided (for now) to only interpret the purest "form" as a parent property hook call. I.e. the class name needs to be |
I'm going for my original patch idea for consistency then.
In OP's code almost right: we're not in a hook context but indeed if I use a hook context it fails here. Which is nice and consistent imo. |
The current code expects the property name to be a string, but it can also be a number via the {} syntax. Handle this consistently to a string by using zval_get_string which will do the type coercion and refcount update (instead of assuming string and doing an explicit string copy).
Description
Hello there.
The following code:
Resulted in this output:
To reproduce:
Additional reference: https://3v4l.org/ZPSua/rfc#vgit.master
PHP Version
Nightly and 8.4.2
Operating System
Ubuntu 22.04
The text was updated successfully, but these errors were encountered: