Professional Web Applications Themes

#40300 [NEW]: Calling a function on a newly created object doesn't work - PHP Bugs

From: finalvoid at gmail dot com Operating system: Windows XP PHP version: 5.2.0 PHP Bug Type: Class/Object related Bug description: Calling a function on a newly created object doesn't work Description: ------------ Calling a function on a newly created object requires saving the object to a variable. Script that clarifies what I'm trying to say: class C { public function __construct() {} public function f() { return 1234; } }; $y = (new C())->f(); print($y); The above doesn't work. However, it does work if you replace the penultimate line with $x = new C(); $y = $x->f(); If we add ...

  1. #1

    Default #40300 [NEW]: Calling a function on a newly created object doesn't work

    From: finalvoid at gmail dot com
    Operating system: Windows XP
    PHP version: 5.2.0
    PHP Bug Type: Class/Object related
    Bug description: Calling a function on a newly created object doesn't work

    Description:
    ------------
    Calling a function on a newly created object requires saving the object to
    a variable. Script that clarifies what I'm trying to say:

    class C
    { public function __construct() {}
    public function f() { return 1234; }
    };
    $y = (new C())->f();
    print($y);

    The above doesn't work. However, it does work if you replace the
    penultimate line with
    $x = new C();
    $y = $x->f();

    If we add parentheses around the $x, i.e.
    $y = ($x)->f();
    then it still doesn't work. This and bug report #9587 indicate that the
    actual underlying cause is that object-valued variables are implemented,
    but object-valued expressions are not.

    Although the "this is not a bug" comment on the above-cited bug report
    #9587 did not include a rationale, it's difficult for me to decide whether
    it applies here as well; maybe this bug report should actually be a feature
    request? Personally, as a PHP rookie but Java veteran, I would say that
    object-valued expressions SHOULD work, and they DON'T, therefore it's a
    BUG.

    Thanks!

    Reproduce code:
    ---------------
    class C
    { public function __construct() {}
    public function f() { return 1234; }
    };
    $y = (new C())->f();
    print($y);

    Expected result:
    ----------------
    1234

    Actual result:
    --------------
    P error: p error, unexpected T_OBJECT_OPERATOR in c:\path\test.php
    on line 5


    --
    Edit bug report at [url]http://bugs.php.net/?id=40300&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40300&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40300&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40300&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40300&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40300&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40300&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40300&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40300&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40300&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40300&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40300&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40300&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40300&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40300&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40300&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40300&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40300&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40300&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40300&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40300&r=mysqlcfg[/url]
    finalvoid at gmail dot com Guest

  2. #2

    Default #40300 [Opn->Bgs]: Calling a function on a newly created object doesn't work

    ID: 40300
    Updated by: [email]derickphp.net[/email]
    Reported By: finalvoid at gmail dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Class/Object related
    Operating System: Windows XP
    PHP Version: 5.2.0
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    This syntax is simply not supported.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-01 00:28:12] finalvoid at gmail dot com

    Description:
    ------------
    Calling a function on a newly created object requires saving the object
    to a variable. Script that clarifies what I'm trying to say:

    class C
    { public function __construct() {}
    public function f() { return 1234; }
    };
    $y = (new C())->f();
    print($y);

    The above doesn't work. However, it does work if you replace the
    penultimate line with
    $x = new C();
    $y = $x->f();

    If we add parentheses around the $x, i.e.
    $y = ($x)->f();
    then it still doesn't work. This and bug report #9587 indicate that
    the actual underlying cause is that object-valued variables are
    implemented, but object-valued expressions are not.

    Although the "this is not a bug" comment on the above-cited bug report
    #9587 did not include a rationale, it's difficult for me to decide
    whether it applies here as well; maybe this bug report should actually
    be a feature request? Personally, as a PHP rookie but Java veteran, I
    would say that object-valued expressions SHOULD work, and they DON'T,
    therefore it's a BUG.

    Thanks!

    Reproduce code:
    ---------------
    class C
    { public function __construct() {}
    public function f() { return 1234; }
    };
    $y = (new C())->f();
    print($y);

    Expected result:
    ----------------
    1234

    Actual result:
    --------------
    P error: p error, unexpected T_OBJECT_OPERATOR in
    c:\path\test.php on line 5



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40300&edit=1[/url]
    derick@php.net Guest

Similar Threads

  1. Page view issues with newly created links
    By Anoek_Minneboo@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: August 1st, 06:40 PM
  2. Permissions for newly created files by FSO
    By Rik Hoeflaak in forum ASP Components
    Replies: 1
    Last Post: February 4th, 01:09 AM
  3. Newly Created Image Not Always Found by Following Code
    By Earl Teigrob in forum ASP.NET General
    Replies: 0
    Last Post: August 5th, 03:39 PM
  4. Permissions wrong on newly created file
    By Ben Phillips in forum SCO
    Replies: 4
    Last Post: July 11th, 02:40 PM
  5. Button created in Access2002 doesn't work in Access2000
    By Joe Strayer in forum Microsoft Access
    Replies: 0
    Last Post: July 7th, 05:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139