3v4l.org

run code in 200+ PHP versions simultaneously
<?php interface Model { public function tableName(): string; } abstract class AbstractTable implements Model { public function tableName(): string { return constant('static::TABLE_NAME'); } } final class SomeTable extends AbstractTable { public const TABLE_NAME = 'some_table'; } $table = new SomeTable(); var_dump($table->tableName()); // $pdo->prepare(sprintf("SELECT * FROM %s", $table->tableName());
Output for 7.1.0 - 7.2.6
string(10) "some_table"
Output for 7.0.0 - 7.0.24
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/kH1qE on line 14
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/kH1qE on line 4
Process exited with code 255.