3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Post { const TABLE = 'posts'; const TYPE = 'post'; static public function all() { $select = "SELECT * FROM `%s` WHERE `type` = '%s'\n"; echo sprintf($select, self::TABLE, self::TYPE); } } Post::all(); class Comment extends Post { const TYPE = 'comment'; } Comment::all(); echo "===\n"; class PostA { const TABLE = 'posts'; const TYPE = 'post'; static public function all() { $select = "SELECT * FROM `%s` WHERE `type` = '%s'\n"; echo sprintf($select, static::TABLE, static::TYPE); } } PostA::all(); // SELECT * FROM `posts` WHERE `type` = 'post' class CommentA extends PostA { const TYPE = 'comment'; } CommentA::all();
based on 2a1u3
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0rc3
SELECT * FROM `posts` WHERE `type` = 'post' SELECT * FROM `posts` WHERE `type` = 'post' === SELECT * FROM `posts` WHERE `type` = 'post' SELECT * FROM `posts` WHERE `type` = 'comment'