Hello everybody,
It's the first time I write on the internals mailing-list, so let me
introduce myself quickly. I'm a french and canadian CTO, working in Paris.
I lead some PHP projects (mainly the Temma framework and FineFS data
replication system).
I begin to learn PHP's internal engine, backed by Pierrick Charron.
I would like to do an RFC proposal (see below for the associated patch).
I was thinking about "what if PHP was a full-object language?". Like, for
example, how will we write the simplest code, assuming that objects are
handled using pointers since PHP 5.
Take a look at this code:
$a = 3;
$b = $a;
$a++;
$b still contains the value 3.
Now, if we imagine that even the integer data type is managed in an object,
the same code will produce two pointers to the same object. Thus, $b will
have the value 4, as $a.
So, in this imaginary world, we would need to do a lot of object cloning. I
wondered how this could be less painful, and I thought about the Pascal
language's affectation operator (:=).
Then we would be able to write something like that:
$a = 3;
$b := $a;
$c = $a;
$a++;
$a equals 4, as $c. But $b equals 3.
Back in the real world, we are not cloning objects very often. But, like
many other syntactic sugars (as the short array syntax), I think it could
be handy in some circumstances.
There is a patch for this evolution, written by Pierrick.
Full source code: https://github.com/adoy/php-src/tree/amaury-clone
Code diff:
https://github.com/adoy/php-src/commit/5107c0355c50381c7e67230cdc9f563eb3936a15
I'm looking forward to your advices.
Cheers!
Amaury
Back in the real world, we are not cloning objects very often. But, like
many other syntactic sugars (as the short array syntax), I think it could
be handy in some circumstances.
Well, arrays are used all over the place. As you said: cloning is not.
Also this patch only covers one use case, the assignment of an copy. I
does not cover other cases, like cloning in an function call
foo(clone $obj);
etc. So I see little need for that sugar, it will mostly hurt the teeth
(to stay in the picture)
johannes
2012/6/29 Amaury Bouchard amaury@amaury.net:
Hello everybody,
It's the first time I write on the internals mailing-list, so let me
introduce myself quickly. I'm a french and canadian CTO, working in Paris.
I lead some PHP projects (mainly the Temma framework and FineFS data
replication system).
I begin to learn PHP's internal engine, backed by Pierrick Charron.I would like to do an RFC proposal (see below for the associated patch).
I was thinking about "what if PHP was a full-object language?". Like, for
example, how will we write the simplest code, assuming that objects are
handled using pointers since PHP 5.Take a look at this code:
$a = 3;
$b = $a;
$a++;$b still contains the value 3.
Now, if we imagine that even the integer data type is managed in an object,
the same code will produce two pointers to the same object. Thus, $b will
have the value 4, as $a.
So, in this imaginary world, we would need to do a lot of object cloning. I
wondered how this could be less painful, and I thought about the Pascal
language's affectation operator (:=).Then we would be able to write something like that:
$a = 3;
$b := $a;
$c = $a;
$a++;$a equals 4, as $c. But $b equals 3.
Back in the real world, we are not cloning objects very often. But, like
many other syntactic sugars (as the short array syntax), I think it could
be handy in some circumstances.There is a patch for this evolution, written by Pierrick.
Full source code: https://github.com/adoy/php-src/tree/amaury-clone
Code diff:
https://github.com/adoy/php-src/commit/5107c0355c50381c7e67230cdc9f563eb3936a15I'm looking forward to your advices.
Cheers!
Amaury
Hi Amaury,
I have to agree with Johannes here, it looks like a benefit only in a
very few cases but introduces a lot of side changes like IDE syntax
parsing, to cite only one.
I really doubt the little benefit of such a change outperforms the
extra work involved.
Cheers,
Patrick
I also agree with Johannes.
Pierrick
2012/6/29 Amaury Bouchard amaury@amaury.net:
Hello everybody,
It's the first time I write on the internals mailing-list, so let me
introduce myself quickly. I'm a french and canadian CTO, working in
Paris.
I lead some PHP projects (mainly the Temma framework and FineFS data
replication system).
I begin to learn PHP's internal engine, backed by Pierrick Charron.I would like to do an RFC proposal (see below for the associated patch).
I was thinking about "what if PHP was a full-object language?". Like, for
example, how will we write the simplest code, assuming that objects are
handled using pointers since PHP 5.Take a look at this code:
$a = 3;
$b = $a;
$a++;$b still contains the value 3.
Now, if we imagine that even the integer data type is managed in an
object,
the same code will produce two pointers to the same object. Thus, $b will
have the value 4, as $a.
So, in this imaginary world, we would need to do a lot of object
cloning. I
wondered how this could be less painful, and I thought about the Pascal
language's affectation operator (:=).Then we would be able to write something like that:
$a = 3;
$b := $a;
$c = $a;
$a++;$a equals 4, as $c. But $b equals 3.
Back in the real world, we are not cloning objects very often. But, like
many other syntactic sugars (as the short array syntax), I think it could
be handy in some circumstances.There is a patch for this evolution, written by Pierrick.
Full source code: https://github.com/adoy/php-src/tree/amaury-clone
Code diff:https://github.com/adoy/php-src/commit/5107c0355c50381c7e67230cdc9f563eb3936a15
I'm looking forward to your advices.
Cheers!
Amaury
Hi Amaury,
I have to agree with Johannes here, it looks like a benefit only in a
very few cases but introduces a lot of side changes like IDE syntax
parsing, to cite only one.
I really doubt the little benefit of such a change outperforms the
extra work involved.Cheers,
Patrick
Yes, guys. I totally understand your point. As I said, I had this idea in a
dreamed context (good or bad dream? I don't know).
But still, I think it's intellectually interesting, even if it's not a good
concept for PHP. :-)
Pierrick, I owe you a beer ;-)
Le 29 juin 2012 19:06, "Pierrick Charron" pierrick@webstart.fr a écrit :
No problem when you'll come in Montreal ! If you need any help don't
hesitate.
Pierrick
Yes, guys. I totally understand your point. As I said, I had this idea in
a dreamed context (good or bad dream? I don't know).
But still, I think it's intellectually interesting, even if it's not a
good concept for PHP. :-)Pierrick, I owe you a beer ;-)
Le 29 juin 2012 19:06, "Pierrick Charron" pierrick@webstart.fr a écrit :
My input is that we should be focusing on features that PHP lacks, or
fixing bugs rather than adding more sugar syntax just for the sake of
adding it.
On Fri, Jun 29, 2012 at 7:47 PM, Pierrick Charron pierrick@webstart.frwrote:
No problem when you'll come in Montreal ! If you need any help don't
hesitate.Pierrick
Yes, guys. I totally understand your point. As I said, I had this idea in
a dreamed context (good or bad dream? I don't know).
But still, I think it's intellectually interesting, even if it's not a
good concept for PHP. :-)Pierrick, I owe you a beer ;-)
Le 29 juin 2012 19:06, "Pierrick Charron" pierrick@webstart.fr a
écrit :
Uhm... &=
My input is that we should be focusing on features that PHP lacks, or
fixing bugs rather than adding more sugar syntax just for the sake of
adding it.On Fri, Jun 29, 2012 at 7:47 PM, Pierrick Charron pierrick@webstart.frwrote:
No problem when you'll come in Montreal ! If you need any help don't
hesitate.Pierrick
Yes, guys. I totally understand your point. As I said, I had this idea in
a dreamed context (good or bad dream? I don't know).
But still, I think it's intellectually interesting, even if it's not a
good concept for PHP. :-)Pierrick, I owe you a beer ;-)
Le 29 juin 2012 19:06, "Pierrick Charron" pierrick@webstart.fr a
écrit :
@Michael : I'm not sure to understand what you mean.
The "&=" operator does a bitwise AND. But if it was an
assignment-by-reference operator, maybe an assignment-by-cloning operator
would have seemed a good idea?
Some people write code using "=&" like a dedicated operator. For example:
$i = 3;
$j =& $i;
(yes, I know they should write "$j = &$i;")
It would be an "inverted equivalent" if we were able to write :
$i = new Int(3);
$j := $i;
2012/6/30 Michael Morris dmgx.michael@gmail.com
Uhm... &=
On Fri, Jun 29, 2012 at 6:09 PM, Paul Dragoonis dragoonis@gmail.com
wrote:My input is that we should be focusing on features that PHP lacks, or
fixing bugs rather than adding more sugar syntax just for the sake of
adding it.On Fri, Jun 29, 2012 at 7:47 PM, Pierrick Charron <pierrick@webstart.fr
wrote:No problem when you'll come in Montreal ! If you need any help don't
hesitate.Pierrick
Yes, guys. I totally understand your point. As I said, I had this
idea in
a dreamed context (good or bad dream? I don't know).
But still, I think it's intellectually interesting, even if it's not a
good concept for PHP. :-)Pierrick, I owe you a beer ;-)
Le 29 juin 2012 19:06, "Pierrick Charron" pierrick@webstart.fr a
écrit :