3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = ' <content> <hello attribute="123"></hello> </content> '; class Parser { private $xml; public function __construct(SimpleXMLElement $xml) { $this->xml = $xml; } public function asString(): string { return $this->getValue(); } public function asInt(): int { return $this->getValue(); } public function asCastedInt(): int { return $this->asString(); } public function directConversion() { return (int)$this->getValue(); } private function getValue() { return $this->xml->hello['attribute']; } } $object = new Parser(new SimpleXMLElement($xml)); var_dump($object->asString()); var_dump($object->asCastedInt()); var_dump($object->directConversion()); var_dump($object->asInt());

preferences:
61.2 ms | 402 KiB | 5 Q