note 126880 added to class.phptoken

From: Date: Fri, 25 Feb 2022 16:19:17 +0000
Subject: note 126880 added to class.phptoken
Groups: php.notes 
Request: Send a blank email to php-notes+get-217655@lists.php.net to get a copy of this message
FIXED VERSION: <?php /** * Tokenizer: PhpToken polyfill. * * @author Fedonyuk Anton <info@ensostudio.ru> * @link https://www.php.net/manual/en/class.phptoken.php */ class PhpToken { /** * @var int */ public $id; /** * @var string */ public $text; /** * @var int */ public $line; /** * @var int */ public $pos; public function __construct(int $id, string $text, int $line = -1, int $position = -1) { $this->id = $id; $this->text = $text; $this->line = $line; $this->pos = $position; } public function getTokenName(): ?string { $name = \token_name($this->id); if ($name === 'UNKNOWN') { $name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text; } return $name; } /** * @param int|string|array $kind */ public function is($kind): bool { $kind = (array) $kind; if (\is_int(\current($kind))) { return \in_array($this->id, $kind, true); } return \in_array($this->text, $kind, true) || \in_array($this->getTokenName(), $kind, true); } public function isIgnorable(): bool { return $this->is([\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_INLINE_HTML]); } public function __toString(): string { return $this->text; } /** * @return static[] */ public static function tokenize(string $code, int $flags = 0): array { $tokens = []; $line = 1; $position = 0; foreach (\token_get_all($code, $flags) as $token) { if (\is_string($token)) { $id = $text = $token; } else { [$id, $text, $line] = $token; } if (\is_string($id)) { $id = \ord($id); } $tokens[] = new static($id, $text, $line, $position); $position += \strlen($text); } return $tokens; } } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 31.129.215.166) ---- Manual Page -- https://php.net/manual/en/class.phptoken.php Edit -- https://main.php.net/note/edit/126880 Del: integrated -- https://main.php.net/note/delete/126880/integrated Del: useless -- https://main.php.net/note/delete/126880/useless Del: bad code -- https://main.php.net/note/delete/126880/bad+code Del: spam -- https://main.php.net/note/delete/126880/spam Del: non-english -- https://main.php.net/note/delete/126880/non-english Del: in docs -- https://main.php.net/note/delete/126880/in+docs Del: other reasons-- https://main.php.net/note/delete/126880 Reject -- https://main.php.net/note/reject/126880 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217655) next »