bg17aw Posted May 24, 2016 Share Posted May 24, 2016 Hi, I am wondering if anyone else can confirm this error, and also can comment on whether it should be reported and how:- page 41, Constant Properties chapter: Constant properties can contain only primitive values. You cannot assign an object to a constant. But objects are also primitive values, as shown here: http://php.net/manual/en/language.types.intro.phpAny thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/301253-constants-error-in-the-book-php-objects-patterns-and-practice-4th-ed/ Share on other sites More sharing options...
Jacques1 Posted May 24, 2016 Share Posted May 24, 2016 You indeed cannot assign objects to constants, so this is more of a wording issue. What exactly can be assigned to class constants depends on the PHP version. Prior to 5.6, you could only have scalar literals (booleans, integers, floats and strings). Then costant expressions (like 1 + 2) were added. And in PHP 7 you can even have arrays. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301253-constants-error-in-the-book-php-objects-patterns-and-practice-4th-ed/#findComment-1533210 Share on other sites More sharing options...
Jacques1 Posted May 25, 2016 Share Posted May 25, 2016 A small correction: Arrays in class constants are already supported by PHP 5.6. PHP 7 merely added support for arrays in runtime constants (the define() construct). Long story short: Instead of “primitive values”, the book should say “constant scalars (or arrays in newer PHP versions)”. Quote Link to comment https://forums.phpfreaks.com/topic/301253-constants-error-in-the-book-php-objects-patterns-and-practice-4th-ed/#findComment-1533226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.