Skip to content
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

issue #126 - don't crash on uninitialized properties #655

Open
wants to merge 1 commit into
base: 4.6.x
Choose a base branch
from

Conversation

pounard
Copy link
Contributor

@pounard pounard commented Sep 12, 2023

I took the liberty of creating a duplicate of #370 that fixes #126.

I have copy/pasted code from the former, but changed the way the guard is implemented by simply writing the extract this way:

try {
    $ret['possibly_unitialized_property'] = $object->possibly_unitialized_property;
} catch (\Error) {}

Hiding engine errors is probably a terrible thing to do, although it works.

There is a question remaining open, should we instead write this ?

try {
    $ret['possibly_unitialized_property'] = $object->possibly_unitialized_property;
} catch (\Error) {
    $ret['possibly_unitialized_property'] = null;
}

I guess simply not setting the value in the array is more representative of what is happening: the value don't get set in the array since it wasn't set at all in the object. I don't care which is the best, both will work for most my use cases, or can be worked around easily.

@pounard pounard force-pushed the fix-uninitialized-properties branch from 10421dc to ce635e0 Compare September 12, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Another one with PHP 7.4
1 participant