com php-src: Rename PhpToken::getAll() to PhpToken::tokenize(): NEWS ext/tokenizer/tests/PhpToken_extension.phpt ext/tokenizer
/tests/PhpToken_extension_errors.phpt ext/tokenizer/tes ts/PhpToken_getAll.phpt ext/tokenizer/tests/PhpToken_me thods.phpt
ext/tokenizer/tests/PhpToken_toString.phpt ext/tokenizer/tests/PhpToken_tokenize.phpt ext/tokeniz er/tests/bug77966.phpt ext/tokenizer/tests/namesp
aced_names.phpt ext/tokenizer/tokenizer.c ext/tokeniz er/t
| From: | Nikita Popov | Date: | Mon, 09 Nov 2020 08:40:31 +0000 |
| Subject: | com php-src: Rename PhpToken::getAll() to PhpToken::tokenize(): NEWS ext/tokenizer/tests/PhpToken_extension.phpt ext/tokenizer /tests/PhpToken_extension_errors.phpt ext/tokenizer/tes ts/PhpToken_getAll.phpt ext/tokenizer/tests/PhpToken_me thods.phpt ext/tokenizer/tests/PhpToken_toString.phpt ext/tokenizer/tests/PhpToken_tokenize.phpt ext/tokeniz er/tests/bug77966.phpt ext/tokenizer/tests/namesp aced_names.phpt ext/tokenizer/tokenizer.c ext/tokeniz er/t |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114083@lists.php.net to get a copy of this message | ||
Commit: b1019f46ed79599df76cad1bc06587083f477b19
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 9 Nov 2020 09:40:31 +0100
Parents: fe2cbcac70e8bbb3246991560c4871c79b8828dd
Branches: PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b1019f46ed79599df76cad1bc06587083f477b19
Log:
Rename PhpToken::getAll() to PhpToken::tokenize()
See https://externals.io/message/112189.
Fixes bug #80328.
Bugs:
https://bugs.php.net/80328
Changed paths:
M NEWS
M ext/tokenizer/tests/PhpToken_extension.phpt
M ext/tokenizer/tests/PhpToken_extension_errors.phpt
D ext/tokenizer/tests/PhpToken_getAll.phpt
M ext/tokenizer/tests/PhpToken_methods.phpt
M ext/tokenizer/tests/PhpToken_toString.phpt
A ext/tokenizer/tests/PhpToken_tokenize.phpt
M ext/tokenizer/tests/bug77966.phpt
M ext/tokenizer/tests/namespaced_names.phpt
M ext/tokenizer/tokenizer.c
M ext/tokenizer/tokenizer.stub.php
M ext/tokenizer/tokenizer_arginfo.h
diff --git a/NEWS b/NEWS index 95aa4618a7f..9e7efeaf974 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,9 @@ PHP NEWS message). (Nikita) . Fixed bug #80266 (parse_url silently drops port number 0). (cmb, Nikita) +- Tokenizer: + . Fixed bug #80328 (PhpToken::getAll() confusing name). (Nikita) + 29 Oct 2020, PHP 8.0.0RC3 - Core: diff --git a/ext/tokenizer/tests/PhpToken_extension.phpt b/ext/tokenizer/tests/PhpToken_extension.phpt index ef1a4f12722..b41843c0604 100644 --- a/ext/tokenizer/tests/PhpToken_extension.phpt +++ b/ext/tokenizer/tests/PhpToken_extension.phpt @@ -20,7 +20,7 @@ class MyPhpToken extends PhpToken { } } -foreach (MyPhpToken::getAll($code) as $token) { +foreach (MyPhpToken::tokenize($code) as $token) { echo $token->getLoweredText(); if ($token->extra !== 123) { diff --git a/ext/tokenizer/tests/PhpToken_extension_errors.phpt b/ext/tokenizer/tests/PhpToken_extension_errors.phpt index d2bee1bc8f4..72164f398cb 100644 --- a/ext/tokenizer/tests/PhpToken_extension_errors.phpt +++ b/ext/tokenizer/tests/PhpToken_extension_errors.phpt @@ -10,7 +10,7 @@ class MyPhpToken1 extends PhpToken { } try { - var_dump(MyPhpToken1::getAll("<?php foo")); + var_dump(MyPhpToken1::tokenize("<?php foo")); } catch (Error $e) { echo $e->getMessage(), "\n"; } @@ -19,7 +19,7 @@ abstract class MyPhpToken2 extends PhpToken { } try { - var_dump(MyPhpToken2::getAll("<?php foo")); + var_dump(MyPhpToken2::tokenize("<?php foo")); } catch (Error $e) { echo $e->getMessage(), "\n"; } diff --git a/ext/tokenizer/tests/PhpToken_getAll.phpt b/ext/tokenizer/tests/PhpToken_getAll.phpt deleted file mode 100644 index 73980b3733d..00000000000 --- a/ext/tokenizer/tests/PhpToken_getAll.phpt +++ /dev/null @@ -1,358 +0,0 @@ ---TEST-- -PhpToken::getAll() method ---SKIPIF-- -<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?> ---FILE-- -<?php - -$code = <<<'PHP' -<?php -function foo() { - echo "bar"; -} -PHP; -var_dump(PhpToken::getAll($code)); -var_dump(PhpToken::getAll($code, TOKEN_PARSE)); - -?> ---EXPECTF-- -array(15) { - [0]=> - object(PhpToken)#1 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(6) "<?php -" - ["line"]=> - int(1) - ["pos"]=> - int(0) - } - [1]=> - object(PhpToken)#2 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(8) "function" - ["line"]=> - int(2) - ["pos"]=> - int(6) - } - [2]=> - object(PhpToken)#3 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(14) - } - [3]=> - object(PhpToken)#4 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(3) "foo" - ["line"]=> - int(2) - ["pos"]=> - int(15) - } - [4]=> - object(PhpToken)#5 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "(" - ["line"]=> - int(2) - ["pos"]=> - int(18) - } - [5]=> - object(PhpToken)#6 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ")" - ["line"]=> - int(2) - ["pos"]=> - int(19) - } - [6]=> - object(PhpToken)#7 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(20) - } - [7]=> - object(PhpToken)#8 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "{" - ["line"]=> - int(2) - ["pos"]=> - int(21) - } - [8]=> - object(PhpToken)#9 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) " - " - ["line"]=> - int(2) - ["pos"]=> - int(22) - } - [9]=> - object(PhpToken)#10 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(4) "echo" - ["line"]=> - int(3) - ["pos"]=> - int(27) - } - [10]=> - object(PhpToken)#11 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(3) - ["pos"]=> - int(31) - } - [11]=> - object(PhpToken)#12 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) ""bar"" - ["line"]=> - int(3) - ["pos"]=> - int(32) - } - [12]=> - object(PhpToken)#13 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ";" - ["line"]=> - int(3) - ["pos"]=> - int(37) - } - [13]=> - object(PhpToken)#14 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " -" - ["line"]=> - int(3) - ["pos"]=> - int(38) - } - [14]=> - object(PhpToken)#15 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "}" - ["line"]=> - int(4) - ["pos"]=> - int(39) - } -} -array(15) { - [0]=> - object(PhpToken)#15 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(6) "<?php -" - ["line"]=> - int(1) - ["pos"]=> - int(0) - } - [1]=> - object(PhpToken)#14 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(8) "function" - ["line"]=> - int(2) - ["pos"]=> - int(6) - } - [2]=> - object(PhpToken)#13 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(14) - } - [3]=> - object(PhpToken)#12 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(3) "foo" - ["line"]=> - int(2) - ["pos"]=> - int(15) - } - [4]=> - object(PhpToken)#11 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "(" - ["line"]=> - int(2) - ["pos"]=> - int(18) - } - [5]=> - object(PhpToken)#10 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ")" - ["line"]=> - int(2) - ["pos"]=> - int(19) - } - [6]=> - object(PhpToken)#9 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(20) - } - [7]=> - object(PhpToken)#8 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "{" - ["line"]=> - int(2) - ["pos"]=> - int(21) - } - [8]=> - object(PhpToken)#7 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) " - " - ["line"]=> - int(2) - ["pos"]=> - int(22) - } - [9]=> - object(PhpToken)#6 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(4) "echo" - ["line"]=> - int(3) - ["pos"]=> - int(27) - } - [10]=> - object(PhpToken)#5 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(3) - ["pos"]=> - int(31) - } - [11]=> - object(PhpToken)#4 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) ""bar"" - ["line"]=> - int(3) - ["pos"]=> - int(32) - } - [12]=> - object(PhpToken)#3 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ";" - ["line"]=> - int(3) - ["pos"]=> - int(37) - } - [13]=> - object(PhpToken)#2 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " -" - ["line"]=> - int(3) - ["pos"]=> - int(38) - } - [14]=> - object(PhpToken)#1 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "}" - ["line"]=> - int(4) - ["pos"]=> - int(39) - } -} diff --git a/ext/tokenizer/tests/PhpToken_methods.phpt b/ext/tokenizer/tests/PhpToken_methods.phpt index 570e8804737..269fdf52777 100644 --- a/ext/tokenizer/tests/PhpToken_methods.phpt +++ b/ext/tokenizer/tests/PhpToken_methods.phpt @@ -15,7 +15,7 @@ function foo() { PHP; // Token names and ignorability. -$tokens = PhpToken::getAll($code); +$tokens = PhpToken::tokenize($code); foreach ($tokens as $i => $token) { printf("[%2d] %-26s %s\n", $i, $token->getTokenName(), $token->isIgnorable() ? "ignorable" : "meaningful"); diff --git a/ext/tokenizer/tests/PhpToken_toString.phpt b/ext/tokenizer/tests/PhpToken_toString.phpt index 17dbfa84a7c..f4b9e8b1186 100644 --- a/ext/tokenizer/tests/PhpToken_toString.phpt +++ b/ext/tokenizer/tests/PhpToken_toString.phpt @@ -3,7 +3,7 @@ PhpToken implements __toString() --FILE-- <?php -$tokens = PhpToken::getAll('<?php echo "Hello ". $what;'); +$tokens = PhpToken::tokenize('<?php echo "Hello ". $what;'); var_dump(implode($tokens)); var_dump($tokens[0] instanceof Stringable); diff --git a/ext/tokenizer/tests/PhpToken_tokenize.phpt b/ext/tokenizer/tests/PhpToken_tokenize.phpt new file mode 100644 index 00000000000..3cf113d75e3 --- /dev/null +++ b/ext/tokenizer/tests/PhpToken_tokenize.phpt @@ -0,0 +1,358 @@ +--TEST-- +PhpToken::tokenize() method +--SKIPIF-- +<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?> +--FILE-- +<?php + +$code = <<<'PHP' +<?php +function foo() { + echo "bar"; +} +PHP; +var_dump(PhpToken::tokenize($code)); +var_dump(PhpToken::tokenize($code, TOKEN_PARSE)); + +?> +--EXPECTF-- +array(15) { + [0]=> + object(PhpToken)#1 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(6) "<?php +" + ["line"]=> + int(1) + ["pos"]=> + int(0) + } + [1]=> + object(PhpToken)#2 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(8) "function" + ["line"]=> + int(2) + ["pos"]=> + int(6) + } + [2]=> + object(PhpToken)#3 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(14) + } + [3]=> + object(PhpToken)#4 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(3) "foo" + ["line"]=> + int(2) + ["pos"]=> + int(15) + } + [4]=> + object(PhpToken)#5 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "(" + ["line"]=> + int(2) + ["pos"]=> + int(18) + } + [5]=> + object(PhpToken)#6 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ")" + ["line"]=> + int(2) + ["pos"]=> + int(19) + } + [6]=> + object(PhpToken)#7 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(20) + } + [7]=> + object(PhpToken)#8 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "{" + ["line"]=> + int(2) + ["pos"]=> + int(21) + } + [8]=> + object(PhpToken)#9 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) " + " + ["line"]=> + int(2) + ["pos"]=> + int(22) + } + [9]=> + object(PhpToken)#10 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(4) "echo" + ["line"]=> + int(3) + ["pos"]=> + int(27) + } + [10]=> + object(PhpToken)#11 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(3) + ["pos"]=> + int(31) + } + [11]=> + object(PhpToken)#12 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) ""bar"" + ["line"]=> + int(3) + ["pos"]=> + int(32) + } + [12]=> + object(PhpToken)#13 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ";" + ["line"]=> + int(3) + ["pos"]=> + int(37) + } + [13]=> + object(PhpToken)#14 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " +" + ["line"]=> + int(3) + ["pos"]=> + int(38) + } + [14]=> + object(PhpToken)#15 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "}" + ["line"]=> + int(4) + ["pos"]=> + int(39) + } +} +array(15) { + [0]=> + object(PhpToken)#15 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(6) "<?php +" + ["line"]=> + int(1) + ["pos"]=> + int(0) + } + [1]=> + object(PhpToken)#14 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(8) "function" + ["line"]=> + int(2) + ["pos"]=> + int(6) + } + [2]=> + object(PhpToken)#13 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(14) + } + [3]=> + object(PhpToken)#12 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(3) "foo" + ["line"]=> + int(2) + ["pos"]=> + int(15) + } + [4]=> + object(PhpToken)#11 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "(" + ["line"]=> + int(2) + ["pos"]=> + int(18) + } + [5]=> + object(PhpToken)#10 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ")" + ["line"]=> + int(2) + ["pos"]=> + int(19) + } + [6]=> + object(PhpToken)#9 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(20) + } + [7]=> + object(PhpToken)#8 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "{" + ["line"]=> + int(2) + ["pos"]=> + int(21) + } + [8]=> + object(PhpToken)#7 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) " + " + ["line"]=> + int(2) + ["pos"]=> + int(22) + } + [9]=> + object(PhpToken)#6 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(4) "echo" + ["line"]=> + int(3) + ["pos"]=> + int(27) + } + [10]=> + object(PhpToken)#5 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(3) + ["pos"]=> + int(31) + } + [11]=> + object(PhpToken)#4 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) ""bar"" + ["line"]=> + int(3) + ["pos"]=> + int(32) + } + [12]=> + object(PhpToken)#3 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ";" + ["line"]=> + int(3) + ["pos"]=> + int(37) + } + [13]=> + object(PhpToken)#2 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " +" + ["line"]=> + int(3) + ["pos"]=> + int(38) + } + [14]=> + object(PhpToken)#1 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "}" + ["line"]=> + int(4) + ["pos"]=> + int(39) + } +} diff --git a/ext/tokenizer/tests/bug77966.phpt b/ext/tokenizer/tests/bug77966.phpt index 142cc7c9aba..db2ed83738c 100644 --- a/ext/tokenizer/tests/bug77966.phpt +++ b/ext/tokenizer/tests/bug77966.phpt @@ -12,7 +12,7 @@ class C { } CODE; -$tokens = PhpToken::getAll($code, TOKEN_PARSE); +$tokens = PhpToken::tokenize($code, TOKEN_PARSE); foreach ($tokens as $token) { echo "{$token->getTokenName()}: \"$token->text\"\n"; } diff --git a/ext/tokenizer/tests/namespaced_names.phpt b/ext/tokenizer/tests/namespaced_names.phpt index 34e947b3525..651524b8e4c 100644 --- a/ext/tokenizer/tests/namespaced_names.phpt +++ b/ext/tokenizer/tests/namespaced_names.phpt @@ -12,7 +12,7 @@ namespace\Foo Foo \ Bar CODE; -foreach (PhpToken::getAll($code) as $token) { +foreach (PhpToken::tokenize($code) as $token) { echo "{$token->getTokenName()}: \"$token->text\"\n"; } diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index d12b5edba8d..7567a270afc 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -92,7 +92,7 @@ static zend_string *php_token_get_text(zval *obj) { static zend_bool tokenize_common( zval *return_value, zend_string *source, zend_long flags, zend_class_entry *token_class); -PHP_METHOD(PhpToken, getAll) +PHP_METHOD(PhpToken, tokenize) { zend_string *source; zend_long flags = 0; diff --git a/ext/tokenizer/tokenizer.stub.php b/ext/tokenizer/tokenizer.stub.php index a3a4246a1af..c329ef49322 100644 --- a/ext/tokenizer/tokenizer.stub.php +++ b/ext/tokenizer/tokenizer.stub.php @@ -9,7 +9,7 @@ function token_name(int $id): string {} class PhpToken implements Stringable { /** @return static[] */ - public static function getAll(string $code, int $flags = 0): array {} + public static function tokenize(string $code, int $flags = 0): array {} final public function __construct(int $id, string $text, int $line = -1, int $pos = -1) {} diff --git a/ext/tokenizer/tokenizer_arginfo.h b/ext/tokenizer/tokenizer_arginfo.h index 8bf694074e2..01d37d406e0 100644 --- a/ext/tokenizer/tokenizer_arginfo.h +++ b/ext/tokenizer/tokenizer_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ef39f4efec05a3ebc5cf56a6b26e01369f00d129 */ + * Stub hash: a06da9ea0191ed78ee7af8f0d9eaccb17dfa4b20 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_get_all, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, code, IS_STRING, 0) @@ -10,7 +10,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_name, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_class_PhpToken_getAll arginfo_token_get_all +#define arginfo_class_PhpToken_tokenize arginfo_token_get_all ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PhpToken___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) @@ -35,7 +35,7 @@ ZEND_END_ARG_INFO() ZEND_FUNCTION(token_get_all); ZEND_FUNCTION(token_name); -ZEND_METHOD(PhpToken, getAll); +ZEND_METHOD(PhpToken, tokenize); ZEND_METHOD(PhpToken, __construct); ZEND_METHOD(PhpToken, is); ZEND_METHOD(PhpToken, isIgnorable); @@ -51,7 +51,7 @@ static const zend_function_entry ext_functions[] = { static const zend_function_entry class_PhpToken_methods[] = { - ZEND_ME(PhpToken, getAll, arginfo_class_PhpToken_getAll, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(PhpToken, tokenize, arginfo_class_PhpToken_tokenize, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(PhpToken, __construct, arginfo_class_PhpToken___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(PhpToken, is, arginfo_class_PhpToken_is, ZEND_ACC_PUBLIC) ZEND_ME(PhpToken, isIgnorable, arginfo_class_PhpToken_isIgnorable, ZEND_ACC_PUBLIC)
diff --git a/NEWS b/NEWS index 95aa4618a7f..9e7efeaf974 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,9 @@ PHP NEWS message). (Nikita) . Fixed bug #80266 (parse_url silently drops port number 0). (cmb, Nikita) +- Tokenizer: + . Fixed bug #80328 (PhpToken::getAll() confusing name). (Nikita) + 29 Oct 2020, PHP 8.0.0RC3 - Core: diff --git a/ext/tokenizer/tests/PhpToken_extension.phpt b/ext/tokenizer/tests/PhpToken_extension.phpt index ef1a4f12722..b41843c0604 100644 --- a/ext/tokenizer/tests/PhpToken_extension.phpt +++ b/ext/tokenizer/tests/PhpToken_extension.phpt @@ -20,7 +20,7 @@ class MyPhpToken extends PhpToken { } } -foreach (MyPhpToken::getAll($code) as $token) { +foreach (MyPhpToken::tokenize($code) as $token) { echo $token->getLoweredText(); if ($token->extra !== 123) { diff --git a/ext/tokenizer/tests/PhpToken_extension_errors.phpt b/ext/tokenizer/tests/PhpToken_extension_errors.phpt index d2bee1bc8f4..72164f398cb 100644 --- a/ext/tokenizer/tests/PhpToken_extension_errors.phpt +++ b/ext/tokenizer/tests/PhpToken_extension_errors.phpt @@ -10,7 +10,7 @@ class MyPhpToken1 extends PhpToken { } try { - var_dump(MyPhpToken1::getAll("<?php foo")); + var_dump(MyPhpToken1::tokenize("<?php foo")); } catch (Error $e) { echo $e->getMessage(), "\n"; } @@ -19,7 +19,7 @@ abstract class MyPhpToken2 extends PhpToken { } try { - var_dump(MyPhpToken2::getAll("<?php foo")); + var_dump(MyPhpToken2::tokenize("<?php foo")); } catch (Error $e) { echo $e->getMessage(), "\n"; } diff --git a/ext/tokenizer/tests/PhpToken_getAll.phpt b/ext/tokenizer/tests/PhpToken_getAll.phpt deleted file mode 100644 index 73980b3733d..00000000000 --- a/ext/tokenizer/tests/PhpToken_getAll.phpt +++ /dev/null @@ -1,358 +0,0 @@ ---TEST-- -PhpToken::getAll() method ---SKIPIF-- -<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?> ---FILE-- -<?php - -$code = <<<'PHP' -<?php -function foo() { - echo "bar"; -} -PHP; -var_dump(PhpToken::getAll($code)); -var_dump(PhpToken::getAll($code, TOKEN_PARSE)); - -?> ---EXPECTF-- -array(15) { - [0]=> - object(PhpToken)#1 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(6) "<?php -" - ["line"]=> - int(1) - ["pos"]=> - int(0) - } - [1]=> - object(PhpToken)#2 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(8) "function" - ["line"]=> - int(2) - ["pos"]=> - int(6) - } - [2]=> - object(PhpToken)#3 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(14) - } - [3]=> - object(PhpToken)#4 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(3) "foo" - ["line"]=> - int(2) - ["pos"]=> - int(15) - } - [4]=> - object(PhpToken)#5 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "(" - ["line"]=> - int(2) - ["pos"]=> - int(18) - } - [5]=> - object(PhpToken)#6 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ")" - ["line"]=> - int(2) - ["pos"]=> - int(19) - } - [6]=> - object(PhpToken)#7 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(20) - } - [7]=> - object(PhpToken)#8 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "{" - ["line"]=> - int(2) - ["pos"]=> - int(21) - } - [8]=> - object(PhpToken)#9 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) " - " - ["line"]=> - int(2) - ["pos"]=> - int(22) - } - [9]=> - object(PhpToken)#10 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(4) "echo" - ["line"]=> - int(3) - ["pos"]=> - int(27) - } - [10]=> - object(PhpToken)#11 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(3) - ["pos"]=> - int(31) - } - [11]=> - object(PhpToken)#12 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) ""bar"" - ["line"]=> - int(3) - ["pos"]=> - int(32) - } - [12]=> - object(PhpToken)#13 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ";" - ["line"]=> - int(3) - ["pos"]=> - int(37) - } - [13]=> - object(PhpToken)#14 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " -" - ["line"]=> - int(3) - ["pos"]=> - int(38) - } - [14]=> - object(PhpToken)#15 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "}" - ["line"]=> - int(4) - ["pos"]=> - int(39) - } -} -array(15) { - [0]=> - object(PhpToken)#15 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(6) "<?php -" - ["line"]=> - int(1) - ["pos"]=> - int(0) - } - [1]=> - object(PhpToken)#14 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(8) "function" - ["line"]=> - int(2) - ["pos"]=> - int(6) - } - [2]=> - object(PhpToken)#13 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(14) - } - [3]=> - object(PhpToken)#12 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(3) "foo" - ["line"]=> - int(2) - ["pos"]=> - int(15) - } - [4]=> - object(PhpToken)#11 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "(" - ["line"]=> - int(2) - ["pos"]=> - int(18) - } - [5]=> - object(PhpToken)#10 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ")" - ["line"]=> - int(2) - ["pos"]=> - int(19) - } - [6]=> - object(PhpToken)#9 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(2) - ["pos"]=> - int(20) - } - [7]=> - object(PhpToken)#8 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "{" - ["line"]=> - int(2) - ["pos"]=> - int(21) - } - [8]=> - object(PhpToken)#7 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) " - " - ["line"]=> - int(2) - ["pos"]=> - int(22) - } - [9]=> - object(PhpToken)#6 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(4) "echo" - ["line"]=> - int(3) - ["pos"]=> - int(27) - } - [10]=> - object(PhpToken)#5 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " " - ["line"]=> - int(3) - ["pos"]=> - int(31) - } - [11]=> - object(PhpToken)#4 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(5) ""bar"" - ["line"]=> - int(3) - ["pos"]=> - int(32) - } - [12]=> - object(PhpToken)#3 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) ";" - ["line"]=> - int(3) - ["pos"]=> - int(37) - } - [13]=> - object(PhpToken)#2 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) " -" - ["line"]=> - int(3) - ["pos"]=> - int(38) - } - [14]=> - object(PhpToken)#1 (4) { - ["id"]=> - int(%d) - ["text"]=> - string(1) "}" - ["line"]=> - int(4) - ["pos"]=> - int(39) - } -} diff --git a/ext/tokenizer/tests/PhpToken_methods.phpt b/ext/tokenizer/tests/PhpToken_methods.phpt index 570e8804737..269fdf52777 100644 --- a/ext/tokenizer/tests/PhpToken_methods.phpt +++ b/ext/tokenizer/tests/PhpToken_methods.phpt @@ -15,7 +15,7 @@ function foo() { PHP; // Token names and ignorability. -$tokens = PhpToken::getAll($code); +$tokens = PhpToken::tokenize($code); foreach ($tokens as $i => $token) { printf("[%2d] %-26s %s\n", $i, $token->getTokenName(), $token->isIgnorable() ? "ignorable" : "meaningful"); diff --git a/ext/tokenizer/tests/PhpToken_toString.phpt b/ext/tokenizer/tests/PhpToken_toString.phpt index 17dbfa84a7c..f4b9e8b1186 100644 --- a/ext/tokenizer/tests/PhpToken_toString.phpt +++ b/ext/tokenizer/tests/PhpToken_toString.phpt @@ -3,7 +3,7 @@ PhpToken implements __toString() --FILE-- <?php -$tokens = PhpToken::getAll('<?php echo "Hello ". $what;'); +$tokens = PhpToken::tokenize('<?php echo "Hello ". $what;'); var_dump(implode($tokens)); var_dump($tokens[0] instanceof Stringable); diff --git a/ext/tokenizer/tests/PhpToken_tokenize.phpt b/ext/tokenizer/tests/PhpToken_tokenize.phpt new file mode 100644 index 00000000000..3cf113d75e3 --- /dev/null +++ b/ext/tokenizer/tests/PhpToken_tokenize.phpt @@ -0,0 +1,358 @@ +--TEST-- +PhpToken::tokenize() method +--SKIPIF-- +<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?> +--FILE-- +<?php + +$code = <<<'PHP' +<?php +function foo() { + echo "bar"; +} +PHP; +var_dump(PhpToken::tokenize($code)); +var_dump(PhpToken::tokenize($code, TOKEN_PARSE)); + +?> +--EXPECTF-- +array(15) { + [0]=> + object(PhpToken)#1 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(6) "<?php +" + ["line"]=> + int(1) + ["pos"]=> + int(0) + } + [1]=> + object(PhpToken)#2 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(8) "function" + ["line"]=> + int(2) + ["pos"]=> + int(6) + } + [2]=> + object(PhpToken)#3 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(14) + } + [3]=> + object(PhpToken)#4 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(3) "foo" + ["line"]=> + int(2) + ["pos"]=> + int(15) + } + [4]=> + object(PhpToken)#5 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "(" + ["line"]=> + int(2) + ["pos"]=> + int(18) + } + [5]=> + object(PhpToken)#6 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ")" + ["line"]=> + int(2) + ["pos"]=> + int(19) + } + [6]=> + object(PhpToken)#7 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(20) + } + [7]=> + object(PhpToken)#8 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "{" + ["line"]=> + int(2) + ["pos"]=> + int(21) + } + [8]=> + object(PhpToken)#9 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) " + " + ["line"]=> + int(2) + ["pos"]=> + int(22) + } + [9]=> + object(PhpToken)#10 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(4) "echo" + ["line"]=> + int(3) + ["pos"]=> + int(27) + } + [10]=> + object(PhpToken)#11 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(3) + ["pos"]=> + int(31) + } + [11]=> + object(PhpToken)#12 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) ""bar"" + ["line"]=> + int(3) + ["pos"]=> + int(32) + } + [12]=> + object(PhpToken)#13 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ";" + ["line"]=> + int(3) + ["pos"]=> + int(37) + } + [13]=> + object(PhpToken)#14 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " +" + ["line"]=> + int(3) + ["pos"]=> + int(38) + } + [14]=> + object(PhpToken)#15 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "}" + ["line"]=> + int(4) + ["pos"]=> + int(39) + } +} +array(15) { + [0]=> + object(PhpToken)#15 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(6) "<?php +" + ["line"]=> + int(1) + ["pos"]=> + int(0) + } + [1]=> + object(PhpToken)#14 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(8) "function" + ["line"]=> + int(2) + ["pos"]=> + int(6) + } + [2]=> + object(PhpToken)#13 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(14) + } + [3]=> + object(PhpToken)#12 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(3) "foo" + ["line"]=> + int(2) + ["pos"]=> + int(15) + } + [4]=> + object(PhpToken)#11 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "(" + ["line"]=> + int(2) + ["pos"]=> + int(18) + } + [5]=> + object(PhpToken)#10 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ")" + ["line"]=> + int(2) + ["pos"]=> + int(19) + } + [6]=> + object(PhpToken)#9 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(2) + ["pos"]=> + int(20) + } + [7]=> + object(PhpToken)#8 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "{" + ["line"]=> + int(2) + ["pos"]=> + int(21) + } + [8]=> + object(PhpToken)#7 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) " + " + ["line"]=> + int(2) + ["pos"]=> + int(22) + } + [9]=> + object(PhpToken)#6 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(4) "echo" + ["line"]=> + int(3) + ["pos"]=> + int(27) + } + [10]=> + object(PhpToken)#5 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " " + ["line"]=> + int(3) + ["pos"]=> + int(31) + } + [11]=> + object(PhpToken)#4 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(5) ""bar"" + ["line"]=> + int(3) + ["pos"]=> + int(32) + } + [12]=> + object(PhpToken)#3 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) ";" + ["line"]=> + int(3) + ["pos"]=> + int(37) + } + [13]=> + object(PhpToken)#2 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) " +" + ["line"]=> + int(3) + ["pos"]=> + int(38) + } + [14]=> + object(PhpToken)#1 (4) { + ["id"]=> + int(%d) + ["text"]=> + string(1) "}" + ["line"]=> + int(4) + ["pos"]=> + int(39) + } +} diff --git a/ext/tokenizer/tests/bug77966.phpt b/ext/tokenizer/tests/bug77966.phpt index 142cc7c9aba..db2ed83738c 100644 --- a/ext/tokenizer/tests/bug77966.phpt +++ b/ext/tokenizer/tests/bug77966.phpt @@ -12,7 +12,7 @@ class C { } CODE; -$tokens = PhpToken::getAll($code, TOKEN_PARSE); +$tokens = PhpToken::tokenize($code, TOKEN_PARSE); foreach ($tokens as $token) { echo "{$token->getTokenName()}: \"$token->text\"\n"; } diff --git a/ext/tokenizer/tests/namespaced_names.phpt b/ext/tokenizer/tests/namespaced_names.phpt index 34e947b3525..651524b8e4c 100644 --- a/ext/tokenizer/tests/namespaced_names.phpt +++ b/ext/tokenizer/tests/namespaced_names.phpt @@ -12,7 +12,7 @@ namespace\Foo Foo \ Bar CODE; -foreach (PhpToken::getAll($code) as $token) { +foreach (PhpToken::tokenize($code) as $token) { echo "{$token->getTokenName()}: \"$token->text\"\n"; } diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index d12b5edba8d..7567a270afc 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -92,7 +92,7 @@ static zend_string *php_token_get_text(zval *obj) { static zend_bool tokenize_common( zval *return_value, zend_string *source, zend_long flags, zend_class_entry *token_class); -PHP_METHOD(PhpToken, getAll) +PHP_METHOD(PhpToken, tokenize) { zend_string *source; zend_long flags = 0; diff --git a/ext/tokenizer/tokenizer.stub.php b/ext/tokenizer/tokenizer.stub.php index a3a4246a1af..c329ef49322 100644 --- a/ext/tokenizer/tokenizer.stub.php +++ b/ext/tokenizer/tokenizer.stub.php @@ -9,7 +9,7 @@ function token_name(int $id): string {} class PhpToken implements Stringable { /** @return static[] */ - public static function getAll(string $code, int $flags = 0): array {} + public static function tokenize(string $code, int $flags = 0): array {} final public function __construct(int $id, string $text, int $line = -1, int $pos = -1) {} diff --git a/ext/tokenizer/tokenizer_arginfo.h b/ext/tokenizer/tokenizer_arginfo.h index 8bf694074e2..01d37d406e0 100644 --- a/ext/tokenizer/tokenizer_arginfo.h +++ b/ext/tokenizer/tokenizer_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ef39f4efec05a3ebc5cf56a6b26e01369f00d129 */ + * Stub hash: a06da9ea0191ed78ee7af8f0d9eaccb17dfa4b20 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_get_all, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, code, IS_STRING, 0) @@ -10,7 +10,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_name, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_class_PhpToken_getAll arginfo_token_get_all +#define arginfo_class_PhpToken_tokenize arginfo_token_get_all ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PhpToken___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) @@ -35,7 +35,7 @@ ZEND_END_ARG_INFO() ZEND_FUNCTION(token_get_all); ZEND_FUNCTION(token_name); -ZEND_METHOD(PhpToken, getAll); +ZEND_METHOD(PhpToken, tokenize); ZEND_METHOD(PhpToken, __construct); ZEND_METHOD(PhpToken, is); ZEND_METHOD(PhpToken, isIgnorable); @@ -51,7 +51,7 @@ static const zend_function_entry ext_functions[] = { static const zend_function_entry class_PhpToken_methods[] = { - ZEND_ME(PhpToken, getAll, arginfo_class_PhpToken_getAll, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(PhpToken, tokenize, arginfo_class_PhpToken_tokenize, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(PhpToken, __construct, arginfo_class_PhpToken___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(PhpToken, is, arginfo_class_PhpToken_is, ZEND_ACC_PUBLIC) ZEND_ME(PhpToken, isIgnorable, arginfo_class_PhpToken_isIgnorable, ZEND_ACC_PUBLIC)