Req #80328 [Opn->Csd]: PhpToken::getAll() confusing name

From: Date: Mon, 09 Nov 2020 08:43:42 +0000
Subject: Req #80328 [Opn->Csd]: PhpToken::getAll() confusing name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230213@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80328&edit=1 ID: 80328 Updated by: nikic@php.net Reported by: david at grudl dot com Summary: PhpToken::getAll() confusing name -Status: Open +Status: Closed Type: Feature/Change Request Package: SPL related PHP Version: 8.0.0RC3 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-11-06 14:02:49] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80328&edit=1

« previous php.bugs (#230213) next »