Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
zend_compile: Add support for %d to sprintf() optimization#14561
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
Changes from all commits
169044ff4f2ebc744c53b9da37d7104a091b012cf8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| --TEST-- | ||
| Test sprintf() function : Rope Optimization for '%d'. | ||
| --FILE-- | ||
| <?php | ||
| function func($num) { | ||
| return $num + 1; | ||
| } | ||
| function sideeffect() { | ||
| echo "Called!\n"; | ||
| return "foo"; | ||
| } | ||
| class Foo { | ||
| public function __construct() { | ||
| echo "Called\n"; | ||
| } | ||
| } | ||
| $a = 42; | ||
| $b = -1337; | ||
| $c = 3.14; | ||
Member 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. Memo to myself, it might make sense to change the sprintf family of functions to emit the deprecation about implicit truncation for floats. | ||
| $d = new stdClass(); | ||
| try { | ||
| var_dump(sprintf("%d", $a)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d", $a, $b)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d", $a, $b, $c)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d/%d", $a, $b, $c, $d)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/", func(0))); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("/%d", func(0))); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("/%d/", func(0))); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d/%d", $a, $b, func(0), $a)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d/%d", __FILE__, __LINE__, 1, M_PI)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d", new Foo(), new Foo(), new Foo(), )); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf('%d/%d/%d', [], [], [])); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| if (PHP_INT_SIZE == 8) { | ||
| var_dump(sprintf('%d/%d/%d', PHP_INT_MAX, 0, PHP_INT_MIN)); | ||
| var_dump("2147483647/0/-2147483648"); | ||
| } else { | ||
| var_dump("9223372036854775807/0/-9223372036854775808"); | ||
| var_dump(sprintf('%d/%d/%d', PHP_INT_MAX, 0, PHP_INT_MIN)); | ||
| } | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf('%d/%d/%d', true, false, true)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d/%d", true, 'foo')); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| try { | ||
| var_dump(sprintf("%d", 'foo')); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| echo "Done"; | ||
| ?> | ||
| --EXPECTF-- | ||
| string(2) "42" | ||
| string(8) "42/-1337" | ||
| string(10) "42/-1337/3" | ||
| Warning: Object of class stdClass could not be converted to int in %s on line 33 | ||
| string(12) "42/-1337/3/1" | ||
| string(2) "1/" | ||
| string(2) "/1" | ||
| string(3) "/1/" | ||
| string(13) "42/-1337/1/42" | ||
| string(8) "0/53/1/3" | ||
| Called | ||
| Called | ||
| Called | ||
| Warning: Object of class Foo could not be converted to int in %s on line 57 | ||
| Warning: Object of class Foo could not be converted to int in %s on line 57 | ||
| Warning: Object of class Foo could not be converted to int in %s on line 57 | ||
| string(5) "1/1/1" | ||
| string(5) "0/0/0" | ||
| string(42) "9223372036854775807/0/-9223372036854775808" | ||
| string(24) "2147483647/0/-2147483648" | ||
| string(5) "1/0/1" | ||
| string(3) "1/0" | ||
| string(1) "0" | ||
| Done | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --TEST-- | ||
| Test sprintf() function : Rope Optimization for '%d' with GMP objects | ||
| --EXTENSIONS-- | ||
| gmp | ||
| --FILE-- | ||
| <?php | ||
| $a = new GMP("42"); | ||
| $b = new GMP("-1337"); | ||
| $c = new GMP("999999999999999999999999999999999"); | ||
| try { | ||
| var_dump(sprintf("%d/%d/%d/%s", $a, $b, $c, $c + 1)); | ||
| } catch (\Throwable $e) {echo $e, PHP_EOL; } echo PHP_EOL; | ||
| echo "Done"; | ||
| ?> | ||
| --EXPECTF-- | ||
| string(63) "42/-1337/4089650035136921599/1000000000000000000000000000000000" | ||
| Done |
Uh oh!
There was an error while loading. Please reload this page.