Skip to content

Conversation

@bp1222
Copy link
Contributor

@bp1222 bp1222 commented Feb 15, 2018

Bug #75921

Add some consistancy when warning about creating a stdObject against an
empty LHS variable. The warning was not being properly reported when
doing a FETCH_OBJ_W.

zval_ptr_dtor_nogc(container);
object_init(container);
if (type != BP_VAR_UNSET) {
if (!make_real_object(container)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I presume the logic in this function was duplicated here because the first branch in it should always be taken in this case. If that's true, then perhaps just adding a zend_error to the original code would be best:

				zval_ptr_dtor_nogc(container);
				object_init(container);
+				zend_error(E_WARNING, "Creating default object from empty value");

If that's not the case, then the logic would look cleaner without a goto jump:

if (type == BP_VAR_UNSET || !make_real_object(container)) {

Copy link
Contributor Author

@bp1222 bp1222 Feb 15, 2018

Choose a reason for hiding this comment

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

We could just as easily add the error here as well, but I went with the reuse the existing function route. I assume this object_init() branch here existed before the function existed, probably explains the bug report. But yes, I mind-farted there, and will apply that fix.

bp1222 added 3 commits March 1, 2018 09:12
Add some consistancy when warning about creating a stdObject against an
empty LHS variable.  The warning was not being properly reported when
doing a FETCH_OBJ_W.
@nikic nikic changed the base branch from master to PHP-7.4 February 12, 2019 10:58
@nikic
Copy link
Member

nikic commented Feb 12, 2019

I was going to say that this kind of change needs an RFC at first, but after looking at the details of the current behavior, I think this change can just go into 7.4. Right now, this warning is always generated for "first-level" operations (with their own opcodes) regardless of whether it's a read or write operation. The warning is not thrown in cases where we don't have a dedicated opcode and go through FETCH_W/RW instead.

The behavior would make some kind of sense if it was separated for read-write vs write operations, but as this is not the case ($obj->prop = $foo warns) I'd say this is just a bug.

return 0;
}
object_init(object);
zend_error(E_WARNING, "Creating default object from empty value");
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to replace the use of make_real_object_rw with make_real_object instead. If you look at that function it has a bunch of special handling to avoid some edge-case memory safety issues, and it's best if we can just reuse it.

@nikic nikic self-assigned this Feb 12, 2019
@nikic
Copy link
Member

nikic commented Feb 14, 2019

I went ahead and rebased this myself. Now merged as e63febb into 7.4+. Thanks, and sorry for the delay :)

@nikic nikic closed this Feb 14, 2019
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.

4 participants