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
signature.asc
Description: OpenPGP digital signature
