php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80328 PhpToken::getAll() confusing name
Submitted: 2020-11-06 14:02 UTC Modified: 2020-11-09 08:43 UTC
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: david at grudl dot com Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 8.0.0RC3 OS:
Private report: No CVE-ID: None
 [2020-11-06 14:02 UTC] david at grudl dot com
Description:
------------
I'm really excited about PHP 8 and it's great that 
object-based alternatives come into language, such as token_get_all().

As you know, there are only 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors.

And this is about naming things :-)


How to call method, whose task is to parse PHP code into tokens? I think it's a good name is `parse()`, even better is `tokenize()`. But it's definitely not a name `get()`, because it obscures what the function does. Get is for getters.


We can add other more specific words to the verb when `tokenize($code)` is not descriptive, like `tokenizeFile()`. But what means `getAll()`? Is there any other option than to get them all? 

getAll() is just an unfortunate name. Side by side with classic getter getTokenName() method - they're similarly named and do a diametrically different job.


For static constructor, also "from" notation might be used, ie PhpToken::fromString(), but please change getAll() to something better :)



BTW: ReflectionAttribute::IS_INSTANCEOF should really be ReflectionAttribute::IS_INSTANCE_OF


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-09 08:43 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-11-09 08:43 UTC] nikic@php.net
Discussed in https://externals.io/message/112189, renamed to PhpToken::tokenize() in https://github.com/php/php-src/commit/b1019f46ed79599df76cad1bc06587083f477b19. Thanks for the suggestion!

> BTW: ReflectionAttribute::IS_INSTANCEOF should really be ReflectionAttribute::IS_INSTANCE_OF

I don't agree with this one. IS_INSTANCEOF mirrors the "instanceof" operator in PHP, and I think it's more valuable to stay consistent with that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 20:01:45 2024 UTC