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. Link to comment 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. Link to comment Share on other sites More sharing options...
Barand Posted September 22, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.