LLLLLLL Posted September 22, 2017 Share Posted September 22, 2017 class foo { // was this always allowed? public $bar = 'abc default value'; // or did older versions only allow this? public $bar; } I couldn't determine the answer to this question looking at documentation. I found some old code where no class had a default value. Maybe it was a developer preference, but I was wondering if older PHP versions didn't even allow default values? Just a question of curiosity. Quote Link to comment https://forums.phpfreaks.com/topic/305080-were-default-property-values-always-allowed/ Share on other sites More sharing options...
requinix Posted September 22, 2017 Share Posted September 22, 2017 Pretty sure they've always allowed it. Literals were fine, but constant expressions public $bar = 'abc' . ' default value';(which sure look constant but technically required some evaluation) are relatively new. Quote Link to comment https://forums.phpfreaks.com/topic/305080-were-default-property-values-always-allowed/#findComment-1551780 Share on other sites More sharing options...
Solution Barand Posted September 22, 2017 Solution Share Posted September 22, 2017 Even back in PHP4 days (when they were defined with "var" instead of "public" etc) you could assign default literal values. Quote Link to comment https://forums.phpfreaks.com/topic/305080-were-default-property-values-always-allowed/#findComment-1551791 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.