3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Osoba{ private $meno; private $priezvisko; private $vek; function __construct($meno,$priezvisko,$vek){ $this->meno = $meno; $this->priezvisko = $priezvisko; $this->vek = $vek; } function get_meno(){ return $this->meno; } function get_priezvisko(){ return $this->priezvisko; } function get_vek(){ return $this->vek; } } function vytvor(){ $a= new Osoba("J","B",30); $b= new Osoba("V","E",12); $c= new Osoba("S","N",78); $d= new Osoba("Q","W",6); $pole=array($a,$b,$c,$d); return $pole; } function vytvorTabulku(){ vytvor(); $table .= '<table>'; foreach($pole as $osoba){ $table .= '<tr>'; $table .= '<td>'.$osoba->get_meno().'</td><td>'.$osoba->get_priezvisko().'</td><td>'.$osoba->get_vek().'</td>'; $table .= '</tr>'; } $table .= '</table>'; return $table; } ?> <!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> <?php echo vytvor(); echo vytvorTabulku(); ?> </table> </body> </html>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> Warning: Array to string conversion in /in/0HbuE on line 60 Array Warning: Undefined variable $table in /in/0HbuE on line 36 Warning: Undefined variable $pole in /in/0HbuE on line 37 Warning: foreach() argument must be of type array|object, null given in /in/0HbuE on line 37 <table></table> </table> </body> </html>
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
<!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> Notice: Array to string conversion in /in/0HbuE on line 60 Array Notice: Undefined variable: table in /in/0HbuE on line 36 Notice: Undefined variable: pole in /in/0HbuE on line 37 Warning: Invalid argument supplied for foreach() in /in/0HbuE on line 37 <table></table> </table> </body> </html>
Output for 7.3.32 - 7.3.33
<!DOCTYPE html> <html> <head> <title>cviko</title> </head> <body> <table> <tr> <td><a href="?order=name">meno</a></td> <td><a href="?order=priezvisko">priezvisko</a></td> <td><a href="?order=vek">vek</a></td> </tr> Array Warning: Invalid argument supplied for foreach() in /in/0HbuE on line 37 <table></table> </table> </body> </html>

preferences:
153.74 ms | 402 KiB | 198 Q