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

The time has come for splat operator #4766

Merged
merged 1 commit into from
Jun 12, 2016

Conversation

orlangur
Copy link
Contributor

No description provided.

- it is possible due to no PHP 5.5 supported anymore
@adragus-inviqa
Copy link
Contributor

adragus-inviqa commented May 31, 2016

/cc #1047

@okorshenko okorshenko merged commit 93af3a1 into magento:develop Jun 12, 2016
okorshenko pushed a commit that referenced this pull request Jun 12, 2016
- removed usage of class reflection for object instantiation in other places
@orlangur orlangur deleted the splat-operator branch June 13, 2016 15:10
@adragus-inviqa
Copy link
Contributor

@orlangur - Don't think our code removes string keys, does it? Haven't looked too much, but I didn't see such a conversion.

@orlangur
Copy link
Contributor Author

@adragus-inviqa this is ObjectManagerFactory internals where arrays are numeric by design. Of course methods available in client code supports string keys.

@vkublytskyi
Copy link

@orlangur, you are right array_values is not necessary at many places where it was added. But as ... operator require numeric array as argument usage of array_values is an implementation based on (operator) interface. Relying on fact that array is already contains numeric keys is an implementation which is based on behavior which leads to code coupling and less stable.

@orlangur
Copy link
Contributor Author

@vkublytskyi, well, to me it looks like besides this PR similar changes were applied everywhere, then noticed that some of them cause fatal error and thus array_values blindly added everywhere which solved a problem but made implementation less elegant.

I didn't know such semantics of the operator thus faced with fatal as well when prepared PR and running tests allowed to catch problems.

As to me there is no justification for sub-optimal implementation in core having such a great unit/integration tests coverage. So, I didn't even touch Zend filter and concrete tests intentionally as such change wouldn't bring significant value but affected by PR placed are participating in hundreds of tests.

Thus it would be better to have the most compact implementation for crucial places like AbstractFactory or Interceptor and keep array_values for everything else, less frequently used.

@orlangur
Copy link
Contributor Author

arrays_values call makes it two times slower (credits to https://phpixie.com/blog/benchmarking-the-php-splat-operator.html):

<?php
function test($a, $b, $c)
{

}

$params = array(1,2,3);

$t = time();
for($i=0; $i<10000000; $i++)
        call_user_func_array('test', $params);
echo time()-$t."\n";


$t = time();
for($i=0; $i<10000000; $i++) 
        test(...array_values($params));
echo time()-$t."\n";

$t = time();
for($i=0; $i<10000000; $i++) 
        test(...$params);
echo time()-$t."\n";
user@hh:~/workspace$ php -f test-splat.php
103
54
27

@okorshenko
Copy link
Contributor

@orlangur as far as I remember you suggested in one of the discussions alternative Reflection framework. Unfortunately I can't find your comment right now. Could you please share your suggestion one more time about alternative library for Reflection.

Thank you

magento-engcom-team pushed a commit that referenced this pull request Sep 17, 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