# Constructor object instance dereferentiation

- Thread: https://externals.io/message/52498
- Original archive: https://news-web.php.net/php.internals/52498
- Started by dukeofgaming on 2011-05-22T04:18:18+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #52498 — dukeofgaming — 2011-05-22T04:18:18+00:00

URL: https://externals.io/message/52498#52498

Hi,

I was wondering if object dereferentiation after constructor call is
something that has been discussed already. This is, being able to do
something like:

new MyClass()->setSomething();

Instead of:

$var = new MyClass();
$var->setSomething();

Regards,

David Vega

---

## #52499 — Ferenc Kovacs — 2011-05-22T08:16:34+00:00

URL: https://externals.io/message/52498#52499 · In reply to: #52498

On Sun, May 22, 2011 at 6:18 AM, dukeofgaming <dukeofgaming@gmail.com>wrote:

> Hi,
>
> I was wondering if object dereferentiation after constructor call is
> something that has been discussed already. This is, being able to do
> something like:
>
> new MyClass()->setSomething();
>
> Instead of:
>
> $var = new MyClass();
> $var->setSomething();
>
> Regards,
>
> David Vega
>

hi.

it was already discussion, Felipe created an RFC and a patch, the responses
was all positive, so I think if nobody changed their mind, we could move
this from Under Discussion to Accepted/Implemented
as I said before, it would be in good pair with the already implemented
array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)

http://marc.info/?l=php-internals&m=129080024516125&w=2
https://wiki.php.net/rfc/instance-method-call

Tyrael

---

## #52500 — dukeofgaming — 2011-05-22T08:33:52+00:00

URL: https://externals.io/message/52498#52500 · In reply to: #52499

>
>
> hi.
>
> it was already discussion, Felipe created an RFC and a patch, the responses
> was all positive, so I think if nobody changed their mind, we could move
> this from Under Discussion to Accepted/Implemented
> as I said before, it would be in good pair with the already implemented
> array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)
>
> http://marc.info/?l=php-internals&m=129080024516125&w=2
> https://wiki.php.net/rfc/instance-method-call
>
> Tyrael
>

Hi,

Nice, it would indeed make sense to include it with array dereferencing.
This feature would enter in the PHP 5.4 release along with array
dereferencing, is this correct?.

Regards,

David

---

## #52501 — Matthew Weier O'Phinney — 2011-05-22T22:05:51+00:00

URL: https://externals.io/message/52498#52501 · In reply to: #52499

> --bcaec52be62721150704a3d8f926
> Content-Type: text/plain; charset=UTF-8
>
> 
> > […]
>
> it was already discussion, Felipe created an RFC and a patch, the responses
> was all positive, so I think if nobody changed their mind, we could move
> this from Under Discussion to Accepted/Implemented
> as I said before, it would be in good pair with the already implemented
> array dereferencing (https://wiki.php.net/rfc/functionarraydereferencing)
>
> http://marc.info/?l=php-internals&m=129080024516125&w=2
> https://wiki.php.net/rfc/instance-method-call

One thing not on the RFC that I'm curious about: if the class defines
__invoke(), would the following work?

    new MyClass()();

That would be particularly useful for implementing helper systems, which
are quite often one-off use cases.

-- 
Matthew Weier O'Phinney
Project Lead            | matthew@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

---

## #52502 — Felipe Pena — 2011-05-23T01:23:47+00:00

URL: https://externals.io/message/52498#52502 · In reply to: #52501

Hi,

2011/5/22 Matthew Weier O'Phinney <weierophinney@php.net>

> One thing not on the RFC that I'm curious about: if the class defines
> __invoke(), would the following work?
>
>    new MyClass()();
>
> That would be particularly useful for implementing helper systems, which
> are quite often one-off use cases.
>
>
No, such feature was not planned in the RFC, the patch doesn't change the
grammar to allow it.

-- 
Regards,
Felipe Pena

---

## #52504 — Jaroslav Hanslik — 2011-05-23T07:42:43+00:00

URL: https://externals.io/message/52498#52504 · In reply to: #52502

Dne 23.5.2011 3:23, Felipe Pena napsal(a):
> Hi,
>
> 2011/5/22 Matthew Weier O'Phinney<weierophinney@php.net>
>
> > […]
> No, such feature was not planned in the RFC, the patch doesn't change the
> grammar to allow it.
>



https://wiki.php.net/rfc/fcallfcall

Jaroslav Hanslik

---

## #52505 — Jaroslav Hanslik — 2011-05-23T07:43:21+00:00

URL: https://externals.io/message/52498#52505 · In reply to: #52502

Dne 23.5.2011 3:23, Felipe Pena napsal(a):
> Hi,
>
> 2011/5/22 Matthew Weier O'Phinney<weierophinney@php.net>
>
> > […]
> No, such feature was not planned in the RFC, the patch doesn't change the
> grammar to allow it.
>



https://wiki.php.net/rfc/fcallfcall

Jaroslav Hanslik
