php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63253 class member access using __invoke() in php5.4
Submitted: 2012-10-10 14:12 UTC Modified: 2014-12-30 18:48 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: schicker03 at gmail dot com Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.7 OS: MacOSX 10.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: schicker03 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-10-10 14:12 UTC] schicker03 at gmail dot com
Description:
------------
As described in that link, class member access is available as of PHP 5.4
>>http://www.php.net/manual/en/migration54.new-features.php, 
>>Class member access on instantiation has been added, e.g. (new Foo)->bar().

My PHP Version is 5.4.0 (not 5.4.7 like showing above, but there`s no choice for 
5.4.0 so I used 5.4.7)

See the sample script, why is that sample not working ?
(new Foo('bar'))();

I don“t know if this is really a bug, but i believe it should work.

best
schicker03

Test script:
---------------
<?php
class Foo
{
    /** @var string */
    protected $bar;

    /**
     * @param string $bar
     */
    public function __construct($bar)
    {
        $this->bar = $bar;
    }

    /**
     * @return null
     */
    public function __invoke()
    {
        echo $this->bar;
    }
}

//works as expected, using __invoke()
$foo = new Foo('bar');
$foo();

//works as expected, calling __invoke()
(new Foo('bar'))->__invoke();

//invalid, but why !? Should work from my point of view
(new Foo('bar'))();

Expected result:
----------------
Expected Result whould be the string bar 3 times:
barbarbar


Patches

instance_invoke_003.phpt (last revision 2012-10-12 04:25 UTC by laruence@php.net)
instance_invoke_002.phpt (last revision 2012-10-12 04:25 UTC by laruence@php.net)
instance_invoke_001.phpt (last revision 2012-10-12 04:24 UTC by laruence@php.net)
bug63253.patch (last revision 2012-10-12 04:15 UTC by laruence@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-11 02:59 UTC] laruence@php.net
-Assigned To: +Assigned To: felipe
 [2012-10-11 16:25 UTC] felipe@php.net
This is not a bug... but a feature request.
 [2012-10-11 16:25 UTC] felipe@php.net
-Status: Assigned +Status: Open -Type: Bug +Type: Feature/Change Request -Assigned To: felipe +Assigned To:
 [2012-10-12 04:08 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63253.patch
Revision:   1350014933
URL:        https://bugs.php.net/patch-display.php?bug=63253&patch=bug63253.patch&revision=1350014933
 [2012-10-12 04:09 UTC] laruence@php.net
An patch is attached, assign to me, will make a rfc later
 [2012-10-12 04:09 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2012-10-12 04:15 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug63253.patch
Revision:   1350015317
URL:        https://bugs.php.net/patch-display.php?bug=63253&patch=bug63253.patch&revision=1350015317
 [2012-10-12 04:24 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: instance_invoke_001.phpt
Revision:   1350015886
URL:        https://bugs.php.net/patch-display.php?bug=63253&patch=instance_invoke_001.phpt&revision=1350015886
 [2012-10-12 04:25 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: instance_invoke_002.phpt
Revision:   1350015907
URL:        https://bugs.php.net/patch-display.php?bug=63253&patch=instance_invoke_002.phpt&revision=1350015907
 [2012-10-12 04:25 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: instance_invoke_003.phpt
Revision:   1350015929
URL:        https://bugs.php.net/patch-display.php?bug=63253&patch=instance_invoke_003.phpt&revision=1350015929
 [2013-05-13 15:52 UTC] treffynnon@php.net
The pull request is now available at https://github.com/php/php-src/pull/301 and 
nickic hopes to have an approved RFC in time for PHP 5.6 (see: 
https://github.com/php/php-src/pull/225#issuecomment-17820247)
 [2014-12-30 18:40 UTC] levim@php.net
I believe this has been implemented in Nikita Popov's uniform syntax RFC which has been merged for PHP 7. I am on mobile so I can't verify this at the moment; perhaps someone else can.
 [2014-12-30 18:48 UTC] requinix@php.net
-Status: Assigned +Status: Closed
 [2014-12-30 18:48 UTC] requinix@php.net
Yup, working in 7. http://3v4l.org/nGuZl
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 15:01:36 2025 UTC