Would be at all possible to implement this kind of shortcut?
echo function(var)[0];
For example, to print the height of an image:
<?
echo getimagesize('./path/to/image')[1];
?>
Sure, if you want more than one of the returned array points, this
would not be very efficient, however when you do only need one, it
would be a lot nicer than:
<?
$tmp = getimagesize('./path/to/image');
echo $tmp[1];
?>
Anyway, just an idea.
-Tig
Hi Tig
2010/6/4 Tig tigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].
[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)
--
regards,
Kalle Sommer Nielsen
kalle@php.net
Hi Tig
2010/6/4 Tig tigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)
Thanks Kalle, I had no idea what it would be called, so I had a hard
time searching for it :]
I noticed that it has been 'declined' - Date: May 01, 2009
(declined), http://wiki.php.net/rfc/functionarraydereferencing
but, as pointed out at point 13 on
http://wiki.php.net/summits/pdmnotesmay09#php_6
function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)
So does this mean array-dereferencing was original declined but still
a possible for PHP 6?
That is how I'm reading it, but just want to make sure.
Again, thanks.
-Tig
Hi,
Has anyone attempted a patch for this? Or does anyone have an idea of
the feasibility? Is it technically possible in a good/clean way?
- Jon
On Fri, Jun 4, 2010 at 11:19 AM, Kalle Sommer Nielsen kalle@php.net
wrote:Hi Tig
2010/6/4 Tig tigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)Thanks Kalle, I had no idea what it would be called, so I had a hard
time searching for it :]I noticed that it has been 'declined' - Date: May 01, 2009
(declined), http://wiki.php.net/rfc/functionarraydereferencingbut, as pointed out at point 13 on
http://wiki.php.net/summits/pdmnotesmay09#php_6function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)So does this mean array-dereferencing was original declined but still
a possible for PHP 6?
That is how I'm reading it, but just want to make sure.Again, thanks.
-Tig
--
--
Jonathan H. Wage (+1 415 992 5468)
Open Source Software Developer & Evangelist
sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org
You should follow me on Twitter: http://www.twitter.com/jwage
You can contact Jonathan about Doctrine, Symfony and Open-Source or for
training, consulting, application development, or business related questions
at jonathan.wage@sensio.com
2010/6/4 Tig tigger.on@gmail.com:
So does this mean array-dereferencing was original declined but still
a possible for PHP 6?
That is how I'm reading it, but just want to make sure.
I belive its because when its been proposed countless times on the
mailing lists, its always been declined (hence why its not in the core
by now). For the PDT I belive it was decided to add both array
dereferencing and call chaining.
I have CC'd stas, perhaps he can give some light on this subject
--
regards,
Kalle Sommer Nielsen
kalle@php.net
Hi!
function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)
I did patch for f()() - it's referenced at
http://wiki.php.net/rfc/fcallfcall - but not for f()[] - didn't have
time for that yet.
It should not be too hard to do, one just has to be careful with
refcounts so that the returned result could be freed properly and
without hurting the referred element.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
2010/6/4 Stas Malyshev smalyshev@sugarcrm.com
Hi!
function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)
I did patch for f()() - it's referenced at
http://wiki.php.net/rfc/fcallfcall - but not for f()[] - didn't have time
for that yet.It should not be too hard to do, one just has to be careful with refcounts
so that the returned result could be freed properly and without hurting the
referred element.
I wrote a patch, but I cannot test all cases, so I'm not sure if is okay at
all.
What about this approach: http://felipe.ath.cx/diff/array_dereference.diff ?
--
Regards,
Felipe Pena
Felipe Pena schreef:
Hi!
2010/6/4 Stas Malyshev smalyshev@sugarcrm.com
Hi!
function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)
I did patch for f()() - it's referenced at
http://wiki.php.net/rfc/fcallfcall - but not for f()[] - didn't have time
for that yet.It should not be too hard to do, one just has to be careful with refcounts
so that the returned result could be freed properly and without hurting the
referred element.I wrote a patch, but I cannot test all cases, so I'm not sure if is okay at
all.What about this approach: http://felipe.ath.cx/diff/array_dereference.diff ?
If the patch is really that easy I'm gonna kill someone. (Or marry you,
depending on my mood :))
Hi all,
2010/6/5 Felipe Pena felipensp@gmail.com
Hi!
2010/6/4 Stas Malyshev smalyshev@sugarcrm.com
Hi!
function call chaining (f()() if f() returns function), and array
dereferencing (f()[0]) - (Stas)
I did patch for f()() - it's referenced at
http://wiki.php.net/rfc/fcallfcall - but not for f()[] - didn't have time
for that yet.It should not be too hard to do, one just has to be careful with refcounts
so that the returned result could be freed properly and without hurting the
referred element.I wrote a patch, but I cannot test all cases, so I'm not sure if is okay at
all.What about this approach: http://felipe.ath.cx/diff/array_dereference.diff?
I've updated the patch, now it works with method call as well.
Example:
<?php
class foo {
public $x = 10;
public function bar() {
$x = array();
$x[] = 3;
$x[] = array(1, 5);
$x[] = new foo;
return $x;
}
}
$foo = new foo;
var_dump($foo->bar()[2]->bar()[0]); // 3
var_dump($foo->bar()[2]->bar()[1]); // array(0 => 1, 1 => 5)
var_dump($foo->bar()[2]->bar()[1][1]); // 5
var_dump($foo->bar()[2]->bar()[2]->x); // 10
function test($arr) {
$x = $arr;
return $x;
}
$array = array(1, new foo);
var_dump(test($array)[0]); // 1
var_dump(test($array)[1]->bar()[0]); // 3
var_dump(test($array)[1]->bar()[2]); // object(foo)
http://felipe.ath.cx/diff/array_dereference.diff
Thanks.
--
Regards,
Felipe Pena
Hi
Why not something more generic.
Someone could think of a ValueNode.
Then it could be use for object, array, any primitive type ...
I will take the ValueNode as a non terminal grammar node.
So first we could do that:
ValueNode->method();
ValueNode::sMethod();
ValueNode[];
foo(ValueNode);
echo ValueNode;
$e = ValueNode;
...
And a ValueNode could be define as:
ValueNode :
NewStatement
| FunctionCall
| PrimitiveValue
| '(' ValueNode ')'
| ...;
This would allow all this syntax:
(new A())->foo();
foo(new A());
foo->bar()[1];
foo()[5];
and many others.
Hi Tig
2010/6/4 Tigtigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)
--Mathieu Suen
Hi
Why not something more generic.
Someone could think of a ValueNode.Then it could be use for object, array, any primitive type ...
I will take the ValueNode as a non terminal grammar node.
So first we could do that:ValueNode->method();
ValueNode::sMethod();
ValueNode[];
foo(ValueNode);
echo ValueNode;
$e = ValueNode;
...And a ValueNode could be define as:
ValueNode :
NewStatement
| FunctionCall
| PrimitiveValue
| '(' ValueNode ')'
| ...;This would allow all this syntax:
(new A())->foo();
foo(new A());
foo->bar()[1];
foo()[5];and many others.
Hi Tig
2010/6/4 Tigtigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)--Mathieu Suen
Not an expert in this area, but does this mechanism limit you to using
single dimensional arrays?
--
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
Hi
Why not something more generic.
Someone could think of a ValueNode.Then it could be use for object, array, any primitive type ...
I will take the ValueNode as a non terminal grammar node.
So first we could do that:ValueNode->method();
ValueNode::sMethod();
ValueNode[];
foo(ValueNode);
echo ValueNode;
$e = ValueNode;
...And a ValueNode could be define as:
ValueNode :
NewStatement | FunctionCall | PrimitiveValue | '(' ValueNode ')' | ...;
This would allow all this syntax:
(new A())->foo();
foo(new A());
foo->bar()[1];
foo()[5];and many others.
Hi Tig
2010/6/4 Tigtigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)--Mathieu Suen
Not an expert in this area, but does this mechanism limit you to using
single dimensional arrays?
Of course not as soon as you add array access to a ValueNode
ValueNode
..
| ArrayAccess
...;
This is very simple and it can refactor greatly the parser.
-- Mathieu Suen
I don't understand what is holding PHP back from having this syntax.
Tig said:
<?
$tmp = getimagesize('./path/to/image');
echo $tmp[1];
?>
The need to assign the trivial variable $tmp first is completely arbitrary.
Is it not a design goal somewhere that languages should allow the greatest
degree of literal expression possible, consistent with existing syntax &
semantics rules?
I am new here but would be interested in helping with a patch (+ hopefully
another RFC) for this. What exactly are the specific arguments against array
dereferencing?
- Harrison
On Fri, Jun 4, 2010 at 4:19 PM, mathieu.suen mathieu.suen@easyflirt.comwrote:
Hi
Why not something more generic.
Someone could think of a ValueNode.Then it could be use for object, array, any primitive type ...
I will take the ValueNode as a non terminal grammar node.
So first we could do that:ValueNode->method();
ValueNode::sMethod();
ValueNode[];
foo(ValueNode);
echo ValueNode;
$e = ValueNode;
...And a ValueNode could be define as:
ValueNode :
NewStatement
| FunctionCall
| PrimitiveValue
| '(' ValueNode ')'
| ...;This would allow all this syntax:
(new A())->foo();
foo(new A());
foo->bar()[1];
foo()[5];and many others.
Hi Tig
2010/6/4 Tigtigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)--Mathieu Suen
Not an expert in this area, but does this mechanism limit you to using
single dimensional arrays?Of course not as soon as you add array access to a ValueNode
ValueNode
..
| ArrayAccess
...;This is very simple and it can refactor greatly the parser.
-- Mathieu Suen
Sorry for the ambiguity in my original message, and thanks to Tig for
PM-ing me about that.
To clarify, I support the syntax for:
echo function(var)[0];
and I believe this syntax:
$tmp = getimagesize('./path/to/image');
echo $tmp[1];
to be awkward and inconvenient. Furthermore, it feels like an
unrefined edge in the PHP syntax because in this case $tmp is a
completely throwaway variable.
While coding I had always wished PHP could have "echo
function(var)[0]" and would like to help make this possible. Are there
any good reasons currently why the RFCs for this aren't getting
accepted?
- Harrison
I don't understand what is holding PHP back from having this syntax.
Tig said:
<?
$tmp = getimagesize('./path/to/image');
echo $tmp[1];
?>The need to assign the trivial variable $tmp first is completely arbitrary. Is it not a design goal somewhere that languages should allow the greatest degree of literal expression possible, consistent with existing syntax & semantics rules?
I am new here but would be interested in helping with a patch (+ hopefully another RFC) for this. What exactly are the specific arguments against array dereferencing?
- Harrison
On 4 June 2010 08:18, mathieu.suenmathieu.suen@easyflirt.com wrote:
Hi
Why not something more generic.
Someone could think of a ValueNode.Then it could be use for object, array, any primitive type ...
I will take the ValueNode as a non terminal grammar node.
So first we could do that:ValueNode->method();
ValueNode::sMethod();
ValueNode[];
foo(ValueNode);
echo ValueNode;
$e = ValueNode;
...And a ValueNode could be define as:
ValueNode :
NewStatement
| FunctionCall
| PrimitiveValue
| '(' ValueNode ')'
| ...;This would allow all this syntax:
(new A())->foo();
foo(new A());
foo->bar()[1];
foo()[5];and many others.
Hi Tig
2010/6/4 Tigtigger.on@gmail.com:
Would be at all possible to implement this kind of shortcut?
Its called array-dereferencing and it was proposed countless times,
including by myself. There is an RFC for this[1] and it was planned on
the old PHP6 todo at the PDT[2].[1] http://wiki.php.net/rfc/functionarraydereferencing
[2] http://wiki.php.net/summits/pdmnotesmay09#php_6 (see point #13)--Mathieu Suen
Not an expert in this area, but does this mechanism limit you to using
single dimensional arrays?Of course not as soon as you add array access to a ValueNode
ValueNode
..
| ArrayAccess
...;This is very simple and it can refactor greatly the parser.
-- Mathieu Suen
Hi,
I've always wondered the same thing too. Would be a nice improvement.
- Jon
Would be at all possible to implement this kind of shortcut?
echo function(var)[0];
For example, to print the height of an image:
<?
echo getimagesize('./path/to/image')[1];
?>Sure, if you want more than one of the returned array points, this
would not be very efficient, however when you do only need one, it
would be a lot nicer than:<?
$tmp = getimagesize('./path/to/image');
echo $tmp[1];
?>Anyway, just an idea.
-Tig
--
--
Jonathan H. Wage (+1 415 992 5468)
Open Source Software Developer & Evangelist
sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org
You should follow me on Twitter: http://www.twitter.com/jwage
You can contact Jonathan about Doctrine, Symfony and Open-Source or for
training, consulting, application development, or business related questions
at jonathan.wage@sensio.com