Skip to content

Latest commit

 

History

History
48 lines (28 loc) · 784 Bytes

namespace_functions.md

File metadata and controls

48 lines (28 loc) · 784 Bytes

Use function in namespace

Explanation

In a presentation by Nikita Popov, he mentions that when you are in a namespaced scope, it might be more performant to use functions in use statements or specify its namespace than to just write it out.

With use

Plot

<?php

namespace Foo;

$array = [1, 2, 3];

$iterations = $argv[1] ?? 1000000;

for ($i = 0; $i < $iterations; $i++) {
    $_ = \count($array);
}

Without use

Plot

<?php

namespace Foo;

$array = [1, 2, 3];

$iterations = $argv[1] ?? 1000000;

for ($i = 0; $i < $iterations; $i++) {
    $_ = count($array);
}