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 8.0.0 - 8.0.12, 8.0.14 - 8.0.24, 8.1.0 - 8.1.11
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) }
Output for 8.0.13
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(https://api.exchangeratesapi.io/latest?base=USD&symbols=BRL): Failed to open stream: No such file or directory 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) }
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.32
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 Notice: Trying to get property 'rates' of non-object in /in/ZcOmX on line 34 Notice: Trying to get property 'BRL' of non-object in /in/ZcOmX on line 34 object(SmartphoneImportado)#2 (1) { ["valor":"SmartphoneImportado":private]=> float(0) }
Output for 7.4.26
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(https://api.exchangeratesapi.io/latest?base=USD&symbols=BRL): failed to open stream: No such file or directory in /in/ZcOmX on line 33 object(SmartphoneImportado)#2 (1) { ["valor":"SmartphoneImportado":private]=> float(0) }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'float' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/ZcOmX on line 9
Process exited with code 255.

preferences:
68.43 ms | 416 KiB | 5 Q