3v4l.org

run code in 300+ PHP versions simultaneously
<?php class table{ //COLUMN NAMES private $cname1 = "ID"; private $cname2 = "name"; private $cname3 = "email"; //etc. //Table private $table1 = "<table align='center'>"; //DOESNT WORK private $table2 = "<table>"; //WORKS public function __construct(){ $this->loadTop(); $this->loadData(); } //loads top row. public function loadTop(){ //If I echo this line it gives the error echo $this->table1."<tr>"; //DOESNT WORK //but If I echo this line there is no problem. echo $this->table2."<tr>"; //WORKS echo "<td>".$this->cname1."</td>"; echo etc."</tr>"; } //loads data from database and adds to table. public function loadData(){ while($row = mysqli_fetch_array($result)){ echo "<tr><td>"; echo $row['ID']; echo etc."</tr>"; } echo "</table>"; } //Now the great thing comes. This does work though. echo $this->table1."<tr><td>Hello</td></tr>"; echo "<tr><td>World</td></tr></table>";
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting function (T_FUNCTION) in /in/eY6Kf on line 42
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_ECHO, expecting T_FUNCTION in /in/eY6Kf on line 42
Process exited with code 255.

preferences:
183.55 ms | 1395 KiB | 66 Q