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

Ask a Question related to PHP Bugs, Design and Development.

  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:
    --------------
    Parse error: parse 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. Similar Questions and Discussions

    1. Page view issues with newly created links
      I just finished creating links on each page of a 200 page document, allowing users to easily jump from section to section. When creating the links I...
    2. Permissions for newly created files by FSO
      Hi there, I'm struggling with this problem: in a website I developed, XML files are created by users of the site to describe. The creation is...
    3. Newly Created Image Not Always Found by Following Code
      I am having a problem where the bitmap image that I just created and saved to disk can not be found but the code in another area of the program....
    4. Permissions wrong on newly created file
      I have two systems unrelated to each other with the same problem. Both systems are running 5.0.5 and have RS505A patch loaded. At the beginning of...
    5. allowing newly created user accounts access to admin account software
      I've just created 2 new user accounts with limited access using windows XP. THe only problem is that they dont have access to software (eg....
  3. #2

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

    ID: 40300
    Updated by: [email]derick@php.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 documentation 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:
    --------------
    Parse error: parse 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

Posting Permissions

  • You may not post new threads
  • You may 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