Hey List,
Just glanced over the Constant Scalar Expressions
RFChttps://wiki.php.net/rfc/const_scalar_exprsand just wanted to
briefly share a couple of thoughts.
This brings initialization of constants, and default values for arguments,
very close to "full" PHP syntax - but not quite.
Did you consider supporting non-scalar values?
Did you consider permitting e.g. function calls in declarations?
And finally, and perhaps most importantly, did you consider lazy (late,
on-access) evaluation of expressions?
I could picture something like the following would go a long way towards
mitigating problems that are currently solved with frameworks and/or oodles
of boilerplate, e.g. when you have a container full of services or
configuration settings etc. without using a framework:
class MyApp {
private $_connection;
public function getConnection() {
if (!isset($this->_connection)) {
$this->_connection = new DatabaseConnection(...);
}
return $this->_connection;
}
public function setConnection(DatabaseConnection $connection) {
$this->_connection = $connection;
}
}
$app = new MyApp;
$db = $app->getConnection(); // lazy initialization
Suppose you had full support for PHP expressions with lazy initialization:
class MyApp {
public $connection = new DatabaseConnection(); // lazy
}
$app = new MyApp;
$db = $app->connection; // lazy initialization
It seems like this would mitigate the need for a lot of framework and/or
boilerplate to achieve lazy construction?
Just putting that out there.
- Rasmus Schultz
Did you consider supporting non-scalar values?
Did you consider permitting e.g. function calls in declarations?
And finally, and perhaps most importantly, did you consider lazy (late,
on-access) evaluation of expressions?
Short answer to this is that those types of cases could (and perhaps
should) be covered by property getter/setters. We could bake it
into the syntax, and it would certainly make the syntax for PHP
scripts look cleaner, but as a first step focusing on constant scalars
only allows us to take a step forward and reevaluate to see where we
are after a version.
-Sara
Good answer - thanks :-)
On Sat, Feb 1, 2014 at 12:11 PM, Rasmus Schultz me@rasmus-schultz.com
wrote:Did you consider supporting non-scalar values?
Did you consider permitting e.g. function calls in declarations?
And finally, and perhaps most importantly, did you consider lazy (late,
on-access) evaluation of expressions?Short answer to this is that those types of cases could (and perhaps
should) be covered by property getter/setters. We could bake it
into the syntax, and it would certainly make the syntax for PHP
scripts look cleaner, but as a first step focusing on constant scalars
only allows us to take a step forward and reevaluate to see where we
are after a version.-Sara