PHP - Classes and Objects
What is wrong with this PHP code?
class Book {
const TITLE = 'PHP Basics';
}
$book = new Book();
echo $book::TITLE;class Book {
const TITLE = 'PHP Basics';
}
$book = new Book();
echo $book::TITLE;Book correctly declares const TITLE = 'PHP Basics';.$book = new Book(); creates an instance, and $book::TITLE is valid syntax to access the class constant from an instance. The code outputs PHP Basics without error.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions