mirror of
https://github.com/php/php-src.git
synced 2026-04-23 16:08:35 +02:00
5a09b9fb0f
RFC: https://wiki.php.net/rfc/token_as_object Relative to the RFC, this also adds a __toString() method, as discussed on list. Closes GH-5176.
37 lines
599 B
PHP
37 lines
599 B
PHP
--TEST--
|
|
Extending the PhpToken class
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("tokenizer")) print "skip tokenizer extension not enabled"; ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
$code = <<<'PHP'
|
|
<?PHP
|
|
FUNCTION FOO() {
|
|
ECHO "bar";
|
|
}
|
|
PHP;
|
|
|
|
class MyPhpToken extends PhpToken {
|
|
public int $extra = 123;
|
|
|
|
public function getLoweredText(): string {
|
|
return strtolower($this->text);
|
|
}
|
|
}
|
|
|
|
foreach (MyPhpToken::getAll($code) as $token) {
|
|
echo $token->getLoweredText();
|
|
|
|
if ($token->extra !== 123) {
|
|
echo "Missing property!\n";
|
|
}
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
<?php
|
|
function foo() {
|
|
echo "bar";
|
|
}
|