Re: Re: [RFC] [Discussion] Class Naming
| From: | Fleshgrinder | Date: | Mon, 03 Jul 2017 15:53:29 +0000 |
| Subject: | Re: Re: [RFC] [Discussion] Class Naming | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99713@lists.php.net to get a copy of this message | ||
On 7/3/2017 5:30 PM, Andreas Treichel wrote:
> With any exception from PascalCase you cannot e.g. generate class names
> from strings without a explicit mapping table:
>
> <?php
>
> function findParserByRootNode(DomDocument $document)
> {
> $tagName = $document->documentElement->tagName;
> $className = ucfirst($tagName) . 'Parser';
> if (!class_exists($className)) {
> throw new RuntimeException('Parser not found for '.$tagName);
> }
> return new $className();
> }
>
> $document = new DomDocument();
> $document->loadXml($xml);
>
> $parser = findParserByRootNode($document);
> $parser->parse($document);
>
>
>
> acronyms in PascalCase looks strange, but consistent strange.
>
>
Not true in PHP because class names are not case sensitive:
https://3v4l.org/bcAAC
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc