rfc:token_as_object
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:token_as_object [2020/02/14 16:22] – nikic | rfc:token_as_object [2020/02/25 15:58] – nikic | ||
---|---|---|---|
Line 27: | Line 27: | ||
/** | /** | ||
* Same as token_get_all(), | * Same as token_get_all(), | ||
- | * @return | + | * @return |
*/ | */ | ||
public static function getAll(string $code, int $flags = 0): array; | public static function getAll(string $code, int $flags = 0): array; | ||
| | ||
- | public function __construct(int $id, string $text, int $line = -1, int $pos = -1); | + | |
} | } | ||
</ | </ | ||
Line 45: | Line 45: | ||
* The token stores the position in the file, so that consumers don't have to compute and store it separately. | * The token stores the position in the file, so that consumers don't have to compute and store it separately. | ||
- | Finally | + | Finally, the tokens take up significantly less memory, and are faster to construct as well. On a large file: |
< | < | ||
Line 55: | Line 55: | ||
Time: 0.32s (for 100 tokenizations) | Time: 0.32s (for 100 tokenizations) | ||
</ | </ | ||
+ | |||
+ | ==== Extensibility ==== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | <PHP> | ||
+ | class MyPhpToken extends PhpToken { | ||
+ | public function getLowerText() { | ||
+ | return strtolower($this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $tokens = MyPhpToken:: | ||
+ | var_dump($tokens[0] instanceof MyPhpToken); | ||
+ | $tokens[0]-> | ||
+ | </ | ||
+ | |||
+ | To guarantee a well-defined construction behavior, the '' | ||
===== Open Questions ===== | ===== Open Questions ===== | ||
Line 102: | Line 120: | ||
/** Get the name of the token. */ | /** Get the name of the token. */ | ||
- | public function getTokenName(): | + | public function getTokenName(): |
if ($this-> | if ($this-> | ||
return chr($this-> | return chr($this-> | ||
+ | } elseif (' | ||
+ | return $name; | ||
} else { | } else { | ||
- | return | + | return |
} | } | ||
} | } | ||
} | } | ||
</ | </ | ||
- | |||
- | ==== Allowing extension of the class ==== | ||
- | |||
- | If the class is extended, should '' | ||
===== Rejected Features ===== | ===== Rejected Features ===== |
rfc/token_as_object.txt · Last modified: 2020/11/12 13:33 by nikic