- var_dump: documentation ( source)
<?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());