Re: Re: [RFC] [Discussion] Class Naming
| From: | Niklas Keller | Date: | Mon, 03 Jul 2017 17:18:52 +0000 |
| Subject: | Re: Re: [RFC] [Discussion] Class Naming | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99720@lists.php.net to get a copy of this message | ||
2017-07-03 17:53 GMT+02:00 Fleshgrinder <php@fleshgrinder.com>:
> 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:
While true, most applications actually depend on the case for class names
because of autoloaders.
Regards, Niklas