3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Carro implements IteratorAggregate { private Peca $motor; private Peca $pneus; private Peca $amortecedor; public function __construct( Peca $motor, Peca $pneus, Peca $amortecedor ) { $this->motor = $motor; $this->pneus = $pneus; $this->amortecedor = $amortecedor; } public function __get($atributo) { return $this->$atributo; } public function __set($atributo, $valor) { $this->$atributo = $valor; } public function getIterator() { return new \ArrayIterator([ $this->motor, $this->pneus, $this->amortecedor, ]); } } class Peca { private string $marca; private string $modelo; private float $preco; public function __construct( ?string $marca, string $modelo, float $preco ) { $this->marca = $marca; $this->modelo = $modelo; $this->preco = $preco; } public function __get($atributo) { return $this->$atributo ; } public function __set($atributo, $valor) { $this->$atributo = $valor; } } $carro = new Carro( new Peca('Teste', "1.8", 15000.00), new Peca("Pirelli", "P7", 500.00), new Peca("Cofap", "ar", 1000.00) ); foreach($carro as $peca){ $peca->marca = "VW"; } var_dump($carro);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Carro::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/4HmUZ on line 29 object(Carro)#1 (3) { ["motor":"Carro":private]=> object(Peca)#2 (3) { ["marca":"Peca":private]=> string(2) "VW" ["modelo":"Peca":private]=> string(3) "1.8" ["preco":"Peca":private]=> float(15000) } ["pneus":"Carro":private]=> object(Peca)#3 (3) { ["marca":"Peca":private]=> string(2) "VW" ["modelo":"Peca":private]=> string(2) "P7" ["preco":"Peca":private]=> float(500) } ["amortecedor":"Carro":private]=> object(Peca)#4 (3) { ["marca":"Peca":private]=> string(2) "VW" ["modelo":"Peca":private]=> string(2) "ar" ["preco":"Peca":private]=> float(1000) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
26.18 ms | 408 KiB | 5 Q