Skip to content

Conversation

@rizwan3d
Copy link

@rizwan3d rizwan3d commented Dec 4, 2025

Implements proposal from #20632

rizwan3d and others added 3 commits December 4, 2025 19:25
@rizwan3d rizwan3d requested a review from mvorisek December 4, 2025 15:52
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also see my comment in #20632 (comment).

return "empty-string";
}

return "non-numeric-string";
Copy link
Member

@iluuu1994 iluuu1994 Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all non-empty strings are non-numeric. You can see this in the tests, it says non-numeric for many examples where one of the strings is actually numeric.

Copy link
Author

@rizwan3d rizwan3d Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To address the issue of numeric strings being reported as "non-numeric string", would adding an is_numeric_string_ex() check like this in zend_zval_numeric_string_value_name() be sufficient?

	zend_long lval;
        double dval;

		bool trailing_data = false;
        if (is_numeric_string_ex(Z_STRVAL_P(val), Z_STRLEN_P(val),&lval, &dval, 0, NULL, &trailing_data)) 
		{
            return "string";
        }
Ref.: ext/opcache/jit/zend_jit_helpers.c:1189
case IS_STRING:
		{
			bool trailing_data = false;
			/* For BC reasons we allow errors so that we can warn on leading numeric string */
			if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
					/* allow errors */ true, NULL, &trailing_data)) {
				if (UNEXPECTED(trailing_data)
				 && EG(current_execute_data)->opline->opcode != ZEND_FETCH_DIM_UNSET) {
					zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
				}
				return offset;
			}
			zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R);
			return 0;
		}

The idea is that empty strings still map to "empty string", non-empty non-numeric strings to "non-numeric string", and numeric strings fall back to "string" so they’re not mislabelled.

@rizwan3d rizwan3d requested a review from iluuu1994 December 4, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants