Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-16 Thread Patrick Schaaf
Am 16.08.2013 01:42 schrieb Stas Malyshev smalys...@sugarcrm.com: But this is not the most tricky part. The most tricky part is this: if(true) return; class Foo { const halfpie = M_PI/2; } Now what happens if this is implemented as an opcode? We can't run any opcodes past return

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Sara Golemon
I have mixed emotions on the yes/no side of things, but on the how side, I think we can do this fairly easily. During parse, when a non-scalar const expression is encountered, the actual binding to the class is deferred, and bytecodes are emitted in the (main) function. To put it in psuedo-code

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Stas Malyshev
Hi! Though obv, in reality we wouldn't use runkit_constant_add(), it'd be a new opcode which had the same effect. This is basically transparent to opcode caches, allows the constant to actually change based on runtime If the class definition can actually change at runtime, I think it'd make

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Johannes Schlüter
On Thu, 2013-08-15 at 16:42 -0700, Stas Malyshev wrote: Hi! Though obv, in reality we wouldn't use runkit_constant_add(), it'd be a new opcode which had the same effect. This is basically transparent to opcode caches, allows the constant to actually change based on runtime If the

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Sara Golemon
if(true) return; class Foo { const halfpie = M_PI/2; } Oooh, excellent point. Wave a finger and tell the user not to do that? I wasn't going to bring this up, but an intersectional idea I had a few years ago Static Constructor. Just like an instance constructor, but called on initial

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Arpad Ray
On Fri, Aug 16, 2013 at 1:00 AM, Sara Golemon poll...@php.net wrote: I wasn't going to bring this up, but an intersectional idea I had a few years ago Static Constructor. Just like an instance constructor, but called on initial load. class Foo { public static __static_construct(/*

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-15 Thread Stas Malyshev
Hi! note that we have this functionality already: $ php -r 'class A { const C = FOO; } define(FOO, 23); echo A::C;' 23 The first fetch will resolve that. This is true, but what happens is that FOO is stored and then resolved on fetch with direct lookup. Now, if C = M_PI/2, what would we

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Christian Stoller
Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. What should that be for? const FOO = 1 + 1; const BAZ = HELLO . WORLD!; Why not just writing

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Sebastian Krebs
Am 14.08.2013 08:17 schrieb Christian Stoller stol...@leonex.de: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. What should that be for?

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Patrick Schaaf
Would this allow using constants, too? Class constants? const FOO = 1; const BAR = self::FOO + 1; const BAZ = self::FOO + 2; const BARF = GLOBAL_BARF; const IMPORT = otherclass::IMPORT; // with autoloading? In my opinion these would start to make the feature useful. Even more useful, but

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Pierre Joye
On Wed, Aug 14, 2013 at 8:17 AM, Christian Stoller stol...@leonex.de wrote: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. What should that be for?

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Julien Pauli
On Tue, Aug 13, 2013 at 6:12 PM, Anthony Ferrara ircmax...@gmail.comwrote: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. for example: const FOO =

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Sebastian Bergmann
Am 13.08.2013 18:12, schrieb Anthony Ferrara: Thoughts? +1 :) -- Sebastian BergmannCo-Founder and Principal Consultant http://sebastian-bergmann.de/ http://thePHP.cc/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Stas Malyshev
Hi! https://wiki.php.net/rfc/const_scalar_expressions I like the idea, but absence of constant support makes this thing much less useful, as you can't do things like: public $angle = M_PI/2; I think this is one of the reasons this idea was never implemented - because without constant support

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Patrick ALLAERT
2013/8/13 Anthony Ferrara ircmax...@gmail.com: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. for example: const FOO = 1 + 1; static $bar = 1 2;

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Michael Wallner
On 14 August 2013 11:01, Stas Malyshev smalys...@sugarcrm.com wrote: Hi! https://wiki.php.net/rfc/const_scalar_expressions I like the idea, but absence of constant support makes this thing much less useful, as you can't do things like: public $angle = M_PI/2; I think this is one of the

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Anthony Ferrara
Stas, On Wed, Aug 14, 2013 at 5:01 AM, Stas Malyshev smalys...@sugarcrm.comwrote: Hi! https://wiki.php.net/rfc/const_scalar_expressions I like the idea, but absence of constant support makes this thing much less useful, as you can't do things like: public $angle = M_PI/2; I think

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Julien Pauli
On Wed, Aug 14, 2013 at 12:44 PM, Anthony Ferrara ircmax...@gmail.comwrote: Stas, On Wed, Aug 14, 2013 at 5:01 AM, Stas Malyshev smalys...@sugarcrm.comwrote: Hi! https://wiki.php.net/rfc/const_scalar_expressions I like the idea, but absence of constant support makes this thing much

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Derick Rethans
On Wed, 14 Aug 2013, Patrick Schaaf wrote: Would this allow using constants, too? Class constants? const FOO = 1; const BAR = self::FOO + 1; const BAZ = self::FOO + 2; const BARF = GLOBAL_BARF; const IMPORT = otherclass::IMPORT; // with autoloading? In my opinion these would start to

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Patrick Schaaf
Am 14.08.2013 13:03 schrieb Derick Rethans der...@php.net: On Wed, 14 Aug 2013, Patrick Schaaf wrote: Would this allow using constants, too? Class constants? const FOO = 1; const BAR = self::FOO + 1; Those are not constants, but expressions which can't be run during compile time.

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Sebastian Krebs
Hi, Just asking: Does this cover only declarations, or every constant expression, for example $weeks = $secs / (60 * 60 * 24 * 7); becomes to the opcode-equivalent of $weeks = $secs / (604800); ? 2013/8/14 Anthony Ferrara ircmax...@gmail.com Stas, On Wed, Aug 14, 2013 at 5:01 AM, Stas

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Anthony Ferrara
Sebastian, On Wed, Aug 14, 2013 at 7:44 AM, Sebastian Krebs krebs@gmail.comwrote: Hi, Just asking: Does this cover only declarations, or every constant expression, for example $weeks = $secs / (60 * 60 * 24 * 7); becomes to the opcode-equivalent of $weeks = $secs / (604800); ?

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Derick Rethans
On Wed, 14 Aug 2013, Anthony Ferrara wrote: Sebastian, On Wed, Aug 14, 2013 at 7:44 AM, Sebastian Krebs krebs@gmail.comwrote: Just asking: Does this cover only declarations, or every constant expression, for example $weeks = $secs / (60 * 60 * 24 * 7); becomes to the

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Lars Strojny
Super cool, thanks! Am 13.08.2013 um 18:12 schrieb Anthony Ferrara ircmax...@gmail.com: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. for

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Bob Weinand
Am 13.08.2013 um 14:13 schrieb Anthony Ferrara ircmax...@gmail.com: Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. for example: const FOO = 1

RE: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Johannes Schlüter
On Wed, 2013-08-14 at 12:03 +0100, Derick Rethans wrote: On Wed, 14 Aug 2013, Patrick Schaaf wrote: Would this allow using constants, too? Class constants? const FOO = 1; const BAR = self::FOO + 1; const BAZ = self::FOO + 2; const BARF = GLOBAL_BARF; const IMPORT =

Re: [PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-14 Thread Stas Malyshev
Hi! Perhaps something for OpCache's optimizer though, if it doesn't already do that... The problem with that is once you start to do conversions, things quicky go south, as conversions can depend on runtime variables, and people get really weird bugs when their expressions are not evaluated

[PHP-DEV] [RFC] Constant Scalar Expressions

2013-08-13 Thread Anthony Ferrara
Hello all, I'd like to propose a new RFC for 5.NEXT: https://wiki.php.net/rfc/const_scalar_expressions This allows for defining constant expressions which are resolved at compile time. for example: const FOO = 1 + 1; static $bar = 1 2; function foo($a = 1 | 2) {} class foo { public $bar