Ask a Question related to PHP Bugs, Design and Development.
-
finalvoid at gmail dot com #1
#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
-
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... -
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... -
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.... -
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... -
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.... -
derick@php.net #2
#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



Reply With Quote

