3v4l.org

run code in 300+ 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.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
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.

preferences:
179.79 ms | 401 KiB | 174 Q