|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33542 If referencing a function that returns a variable, error occurs
Submitted: 2005-07-01 23:47 UTC Modified: 2005-07-29 23:39 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: rick dot martinez at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-07-01 (dev) OS: All
Private report: No CVE-ID: None
 [2005-07-01 23:47 UTC] rick dot martinez at gmail dot com
I have a static function that is supposed to return an instance of an object.

$object = &Object2::getObject();

This works perfectly in PHP but breaks in PHP5.0.x CVS. It returns error:

* Only variables should be assigned by reference

If I create an instance for that variable first, it gets fixed.

$object = new object;
$object = &Object2::getObject();

Is this proper behavior or is this some sort of bug? If it is proper behavior, please change this back. It breaks a LOT of my code. Thanks.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-02 12:12 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.
 [2005-07-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-07-29 22:06 UTC] luciano_closs at hotmail dot com
I have the same error. I suppose that I don't need to get a xml parser by reference, I do not analyse all the code yet, since this code was get from an Open Source Project.

I posted a sample code at:
 [2005-07-29 23:35 UTC] luciano_closs at hotmail dot com
And about the last post: I'm using PHP 4.4.1.
 [2005-07-29 23:39 UTC] rick dot martinez at gmail dot com
This bug was resolved by changing some code.

If you add a & before the name of the function in the function declaration:

function &myFunction() { }

it allows it to be passed as a reference. Hope this helps.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jun 14 21:01:26 2021 UTC