-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Cleanup/#7095 php 5.3 support end #4
Changes from 2 commits
6ad0fd6
54d38a2
065f6ea
8488beb
da7729f
758177e
e38b533
c8e70e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,10 @@ class CallbackHandler | |
/** | ||
* PHP version is greater as 5.4rc1? | ||
* @var bool | ||
* | ||
* @deprecated since 2.4 | ||
*/ | ||
protected static $isPhp54; | ||
protected static $isPhp54 = true; | ||
|
||
/** | ||
* Constructor | ||
|
@@ -85,14 +87,9 @@ public function call(array $args = array()) | |
{ | ||
$callback = $this->getCallback(); | ||
|
||
// Minor performance tweak, if the callback gets called more than once | ||
if (!isset(static::$isPhp54)) { | ||
static::$isPhp54 = version_compare(PHP_VERSION, '5.4.0rc1', '>='); | ||
} | ||
|
||
$argCount = count($args); | ||
|
||
if (static::$isPhp54 && is_string($callback)) { | ||
if (is_string($callback)) { | ||
$result = $this->validateStringCallbackFor54($callback); | ||
|
||
if ($result !== true && $argCount <= 3) { | ||
|
@@ -103,34 +100,22 @@ public function call(array $args = array()) | |
} | ||
} | ||
|
||
// Minor performance tweak; use call_user_func() until > 3 arguments | ||
// Minor performance tweak; use call_user_func_array() with > 3 arguments | ||
// reached | ||
switch ($argCount) { | ||
case 0: | ||
if (static::$isPhp54) { | ||
return $callback(); | ||
} | ||
return call_user_func($callback); | ||
return $callback(); | ||
case 1: | ||
if (static::$isPhp54) { | ||
return $callback(array_shift($args)); | ||
} | ||
return call_user_func($callback, array_shift($args)); | ||
return $callback(array_shift($args)); | ||
case 2: | ||
$arg1 = array_shift($args); | ||
$arg2 = array_shift($args); | ||
if (static::$isPhp54) { | ||
return $callback($arg1, $arg2); | ||
} | ||
return call_user_func($callback, $arg1, $arg2); | ||
return $callback($arg1, $arg2); | ||
case 3: | ||
$arg1 = array_shift($args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
$arg2 = array_shift($args); | ||
$arg3 = array_shift($args); | ||
if (static::$isPhp54) { | ||
return $callback($arg1, $arg2, $arg3); | ||
} | ||
return call_user_func($callback, $arg1, $arg2, $arg3); | ||
return $callback($arg1, $arg2, $arg3); | ||
default: | ||
return call_user_func_array($callback, $args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, that would bring the whole method back to its state before 6f18994 i got ridden of the shifts, it should be the right compromise now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But is there any real benefit of using a switch condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm let's wait for some benchmarks and then re-evaluate. for the time being, we're just leaving it a little bit better than before :) |
||
} | ||
|
@@ -173,8 +158,6 @@ public function getMetadatum($name) | |
/** | ||
* Validate a static method call | ||
* | ||
* Validates that a static method call in PHP 5.4 will actually work | ||
* | ||
* @param string $callback | ||
* @return true|array | ||
* @throws Exception\InvalidCallbackException if invalid | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be
$args[0]
and$args[1]
instead?