3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Produto { public function getNome(): string; public function setValor(float $valor); } class SmartphoneImportado implements Produto { private float $valor; public function getNome(): string { return "Smartphone Importado XPTO"; } public function setValor(float $valor) { $this->valor = $valor; } } abstract class ProdutoFactory { public abstract function criarProduto(): Produto; public function get(): Produto { return $this->criarProduto(); } } class SmartphoneImportadoFactory extends ProdutoFactory { private const URI_API = 'https://api.exchangeratesapi.io/latest?base=USD&symbols=BRL'; public function criarProduto(): \Produto { $cotacao_json = json_decode(file_get_contents(self::URI_API)); $cotacao = $cotacao_json->rates->BRL; $produto = new SmartphoneImportado(); $produto->setValor($cotacao * 100); return $produto; } } $factory = new SmartphoneImportadoFactory(); $produto = $factory->criarProduto(); var_dump($produto);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/ZcOmX on line 33 Warning: file_get_contents(): open_basedir restriction in effect. File(https://api.exchangeratesapi.io/latest?base=USD&symbols=BRL) is not within the allowed path(s): (/tmp:/in:/etc) in /in/ZcOmX on line 33 Warning: file_get_contents(https://api.exchangeratesapi.io/latest?base=USD&symbols=BRL): Failed to open stream: Operation not permitted in /in/ZcOmX on line 33 Warning: Attempt to read property "rates" on null in /in/ZcOmX on line 34 Warning: Attempt to read property "BRL" on null in /in/ZcOmX on line 34 object(SmartphoneImportado)#2 (1) { ["valor":"SmartphoneImportado":private]=> float(0) }

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:
69.1 ms | 402 KiB | 8 Q