Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Sebastian Bergmann
Am 15.03.2017 um 23:33 schrieb Marco Pivetta: > Also the only way to get all properties from an instance of an inheritance > tree. I use the Reflection API in https://github.com/sebastianbergmann/object-reflector/blob/master/src/ObjectReflector.php#L24 for retrieving inherited non-public

[PHP-DEV] UGLY Benchmark Results for PHP Master 2017-03-14

2017-03-15 Thread lp_benchmark_robot
Results for project PHP master, build date 2017-03-14 20:29:38-07:00 commit: 8a7a141 previous commit:edcabf6 revision date: 2017-03-15 00:09:59+01:00 environment:Haswell-EP cpu:Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz 2x18 cores, stepping 2, LLC 45 MB

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
As just told: existing code hinting against generic `object` breaks. This is a change in semantics in an existing operator. It is just sane to consider it a BC break, since the operator cannot be relied upon for a certain family of problems: invent a new operator. That's basically the path to

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Andrey Andreev
On Mar 16, 2017 2:01 AM, "Marco Pivetta" wrote: What changes is the interface of the `(array)` operator. I understand what you mean, I just disagree that it constitutes a BC break in the sense that no existing code would break/misbehave by simply updating to a PHP version

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
What changes is the interface of the `(array)` operator. On 16 Mar 2017 12:53 a.m., "Andrey Andreev" wrote: > Hi, > > On Thu, Mar 16, 2017 at 1:33 AM, Marco Pivetta wrote: > > Correct: passing an object that implements `__toArray()` to an API that > > uses

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Andrey Andreev
Hi, On Thu, Mar 16, 2017 at 1:33 AM, Marco Pivetta wrote: > Correct: passing an object that implements `__toArray()` to an API that > uses an `(array)` cast internally will break or misbehave, if this feature > is added to the language. > I'm not particularly interested in

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
Correct: passing an object that implements `__toArray()` to an API that uses an `(array)` cast internally will break or misbehave, if this feature is added to the language. On 16 Mar 2017 12:27 a.m., "Ryan Pallas" wrote: > > > On Mar 15, 2017 5:03 PM, "Marco Pivetta"

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Ryan Pallas
On Mar 15, 2017 5:03 PM, "Marco Pivetta" wrote: Hi Ryan, I'm top-posting because I'm writing from a phone. I always do and I also stopped caring for top-posters myself because it's fairly normal, plus modern email clients deal with it. If I can write a damn mail from a phone

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
Hi Ryan, I'm top-posting because I'm writing from a phone. I always do and I also stopped caring for top-posters myself because it's fairly normal, plus modern email clients deal with it. If I can write a damn mail from a phone keyboard because I don't have any better right now, then you can

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Ryan Pallas
On Mar 15, 2017 16:40, "Marco Pivetta" wrote: Which is precisely the BC break: such a library would now throw an exception "unsupported class X" when `__toString` is implemented. Also, such a library would break silently when this feature is implemented. Much like the

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Benoît Burnichon
I was not aware of all that being the only way to distinguish set/unset properties. I do agree with Marco on this point that it would be a BC break. It was not my intention at all and did not foresee that. Up to now, I thought array casting objects was doing the same as for scalar values. I was

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Fleshgrinder
On 3/15/2017 11:40 PM, Marco Pivetta wrote: > Which is precisely the BC break: such a library would now throw an > exception "unsupported class X" when `__toString` is implemented. Also, > such a library would break silently when this feature is implemented. > > Much like the already very broken

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
Which is precisely the BC break: such a library would now throw an exception "unsupported class X" when `__toString` is implemented. Also, such a library would break silently when this feature is implemented. Much like the already very broken `__debugInfo()`, this automatic type-cast is a

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Ryan Pallas
On Wed, Mar 15, 2017 at 4:33 PM, Marco Pivetta wrote: > It's the only way to distinguish between set and unset properties. Also the > only way to get all properties from an instance of an inheritance tree. > Also, it's covered by tests that were explicitly added to prevent >

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
It's the only way to distinguish between set and unset properties. Also the only way to get all properties from an instance of an inheritance tree. Also, it's covered by tests that were explicitly added to prevent regressions on this. Same as all similar discussions before this one: need an

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Kalle Sommer Nielsen
Hi 2017-03-15 21:41 GMT+01:00 Marco Pivetta : > This is a BC break due to the fact that the `(array)` cast is used to > extract property information from private properties in library code. Yep, but then again that is more of an undocumented-not-really-supported case afair,

Re: [PHP-DEV] Unexpected results from constant folding

2017-03-15 Thread Sara Golemon
On Wed, Mar 15, 2017 at 4:14 PM, Nikita Popov wrote: > Fixed in 7.1 by > https://github.com/php/php-src/commit/2bba4a0d7f6d5e5712d60bc1cf2119622d837e55. > Thanks! > I personally don't consider a PHP 7.0 backport worthwhile, as this is a long > standing issue (from early PHP

Re: [PHP-DEV] Unexpected results from constant folding

2017-03-15 Thread Nikita Popov
On Wed, Mar 15, 2017 at 3:53 PM, Sara Golemon wrote: > On Wed, Mar 15, 2017 at 5:36 AM, Nikita Popov > wrote: > > Yes, this should behave as C. See also https://bugs.php.net/bug.php? > id=69676 > > for an existing bug report on the topic. > > > Given that

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Marco Pivetta
This is a BC break due to the fact that the `(array)` cast is used to extract property information from private properties in library code. On 15 Mar 2017 6:50 p.m., "Benoît Burnichon" wrote: > Hi all, > > Looking at code of PHPUnit, I stumbled upon an inconsistent array >

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Fleshgrinder
On 3/15/2017 6:49 PM, Benoît Burnichon wrote: > Hi all, > > Looking at code of PHPUnit, I stumbled upon an inconsistent array > conversion: > > -- > /** > * @param ArrayAccess|array $other > */ > function evaluate($other) > { > // type cast $other as an array to allow > //support in

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Benoît Burnichon
> > > Same restrictions could be applied to this magic method: > > > http://us3.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring > > > > By this, I mean, no exceptions should be thrown in this method and return > > value MUST be an array. > > Exceptions cannot be thrown from

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Andrey Andreev
Hi, On Wed, Mar 15, 2017 at 8:31 PM, Benoît Burnichon wrote: >> I like the idea kind of, but would this remove the ability to cast to >> array all classes not implementing __toArray, as is the case with >> __toString? This would be a HUGE BC if so: >> >> $ php -r 'class Foo

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Benoît Burnichon
> I like the idea kind of, but would this remove the ability to cast to > array all classes not implementing __toArray, as is the case with > __toString? This would be a HUGE BC if so: > > $ php -r 'class Foo {public $foo = "foobar";} var_dump((array) (new Foo));' > array(1) { > ["foo"]=> >

Re: [PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Ryan Pallas
On Wed, Mar 15, 2017 at 11:49 AM, Benoît Burnichon wrote: > Hi all, > > Looking at code of PHPUnit, I stumbled upon an inconsistent array > conversion: > > -- > /** > * @param ArrayAccess|array $other > */ > function evaluate($other) > { > // type cast $other as an

[PHP-DEV] Add __toArray() method to objects that would be called on cast to array

2017-03-15 Thread Benoît Burnichon
Hi all, Looking at code of PHPUnit, I stumbled upon an inconsistent array conversion: -- /** * @param ArrayAccess|array $other */ function evaluate($other) { // type cast $other as an array to allow //support in standard array functions. if ($other instanceof ArrayAccess) { $data

Re: [PHP-DEV] [PATCH] Make var_export() output "(object)array(..."instead of "stdClass::__set_state(..." for stdClass

2017-03-15 Thread Andrea Faulds
Hi Marc, Marc Bennewitz wrote: Personally I would like to have a more reasonable way in general. No special case and no magic method. So my proposal then would be to try to add a class cast operator (needs an own RFC) and later to with this approach on var_export. I've wondered if this

Re: [PHP-DEV] Unexpected results from constant folding

2017-03-15 Thread Sara Golemon
On Wed, Mar 15, 2017 at 5:36 AM, Nikita Popov wrote: > Yes, this should behave as C. See also https://bugs.php.net/bug.php?id=69676 > for an existing bug report on the topic. > Given that bug is assigned to you, I'll just leave it in your hands then? > I think in 7.1 it

Re: [PHP-DEV] Unexpected results from constant folding

2017-03-15 Thread David Rodrigues
Just to make simpler to visualize this issue: https://3v4l.org/ZhYlm ```php class Foo { const A = 'Foo::A'; const B = self::A . ' and ' . self::C; const C = 'Foo::C'; } class Bar extends Foo { const A = 'Bar::A'; const C = 'Bar::C'; } var_dump(Bar::B); ``` You should note

Re: [PHP-DEV] Unexpected results from constant folding

2017-03-15 Thread Nikita Popov
On Wed, Mar 15, 2017 at 3:43 AM, Sara Golemon wrote: > This comes in thanks to my old friend Fred Emmott on the HHVM project: > https://3v4l.org/vUHq3 > > class Foo { > const A = 1 << 0; > const B = self::A | self::C; > const C = 1 << 1; > > } > > class Bar extends

Re: [PHP-DEV] OPcache compilation performance regression in PHP 5.6/7 with huge classes

2017-03-15 Thread David Zuelke
On 14 Mar 2017, at 16:39, Nikita Popov wrote: > > On Tue, Mar 14, 2017 at 11:29 AM, David Zuelke wrote: >> Hi all, >> >> There appears to be a performance regression in the CFG and DFA based >> optimization passes of OPcache in PHP 5.6+ when loading huge

Re: [PHP-DEV] array_values should be a no-op for packed layout arrays

2017-03-15 Thread Julien Pauli
On Wed, Mar 15, 2017 at 12:58 AM, Jesse Schalken wrote: > > On Wed, Mar 15, 2017 at 10:39 AM, Sara Golemon wrote: > >> >> Oh yeah, btw... six hours ago... >> https://github.com/php/php-src/commit/c74bc87c74f48bc55541b3 >> bf2fc67d595f58a3b5 >> >> -Sara