Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Private members from the same class - grouping #10

Open
Ocramius opened this issue Jul 18, 2013 · 2 comments
Open

Private members from the same class - grouping #10

Ocramius opened this issue Jul 18, 2013 · 2 comments

Comments

@Ocramius
Copy link
Owner

When reading private class members, we usually do a function call per-property:

$prop1 = Closure::bind(function ($o) { return $o->prop1; }, null, 'ClassName');
$prop2 = Closure::bind(function ($o) { return $o->prop2; }, null, 'ClassName');

return array(
    'prop1' => $prop1($object),
    'prop2' => $prop2($object),
);

If prop1 and prop2 have the same declaring class, the method call can be simply one:

$props = Closure::bind(function ($o) {
    return array($o->prop1, $o->prop2);
}, null, 'ClassName');

list($prop1, $prop2) = $props($object);

return array(
    'prop1' => $prop1,
    'prop2' => $prop2,
);

Same could be done with just arrays:

$data = $props($object);

return array(
    'prop1' => $data[0],
    'prop2' => $data[1],
);

Comparison still to be done, but list may be faster

@Ocramius
Copy link
Owner Author

Note: this may actually be interesting when using by-ref access, so it won't be implemented until a way to use it effectively for writes is found.

@pounard
Copy link
Contributor

pounard commented Jan 11, 2017

I actually did fix that in #59

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants