Professional Web Applications Themes

#24477 [Com]: Problem returning new class by ref from function - PHP Development

ID: 24477 Comment by: jsemczyk at elv dot enic dot fr Reported By: karl at karlaustin dot com Status: Verified Bug Type: Zend Engine 2 problem Operating System: RH7.3 PHP Version: 5CVS-2003-07-03 (dev) New Comment: I have the same error, it seems like it comes from a function that must return a reference, but objects are already references. this doesn't work, but worked before beta1, I tried PEAR before beta1 and it uses lots of this : function &myFunc() { return new MyClass(); } This works fine : function myFunc() { return new MyClass(); } I don't understand why it ...

  1. #1

    Default #24477 [Com]: Problem returning new class by ref from function

    ID: 24477
    Comment by: jsemczyk at elv dot enic dot fr
    Reported By: karl at karlaustin dot com
    Status: Verified
    Bug Type: Zend Engine 2 problem
    Operating System: RH7.3
    PHP Version: 5CVS-2003-07-03 (dev)
    New Comment:

    I have the same error, it seems like it comes from a function that must
    return a reference, but objects are already references.

    this doesn't work, but worked before beta1, I tried PEAR before beta1
    and it uses lots of this :

    function &myFunc()
    {
    return new MyClass();
    }

    This works fine :

    function myFunc()
    {
    return new MyClass();
    }

    I don't understand why it comes from return (new Class()); cause it
    doesn't work.


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

    [2003-07-03 07:09:44] karl at karlaustin dot com

    Well from the text of that item it would suggest that doing:

    return new object();

    is fine, but:

    return (new object());

    is not fine, that's how it would seem to me as an end user.

    PEAR is ridled with returns like the one I list (Although IMHO it
    should have only one return and assign return values to a variable then
    return at the end, but that's another story).

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

    [2003-07-03 06:17:54] [email]derickphp.net[/email]

    Cause:
    [url]http://news.php.net/article.php?group=php.zend-engine.cvs&article=1432[/url]

    I wonder if we really should break BC here...

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

    [2003-07-03 06:13:42] karl at karlaustin dot com

    Description:
    ------------
    Fatal error: Only variables or references can be returned by reference
    in /usr/local/php5/lib/php/DB/common.php on line 737

    If seems that doing:

    return new DB_result($this, $result);

    in a function results in the above error, but:

    $_tmp = new DB_result($this, $result);
    return $_tmp;

    Is fine.



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


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

    jsemczyk at elv dot enic dot fr Guest

  2. #2

    Default #24477 [Com]: Problem returning new class by ref from function

    ID: 24477
    Comment by: jsemczyk at elv dot enic dot fr
    Reported By: karl at karlaustin dot com
    Status: Feedback
    Bug Type: Zend Engine 2 problem
    Operating System: RH7.3
    PHP Version: 5CVS-2003-07-03 (dev)
    New Comment:

    I think it is the same problem as here :
    [url]http://bugs.php.net/bug.php?id=24687[/url]

    As zeev said, in the current zend2 you can't connect to a returned
    value.

    But it is really needed to unreference returned value, and you can do
    it in most object oriented languages.

    Here, we break a compatibilty with PEAR, Horde (and other projects I
    guess). For now, I am waiting for a new version of PEAR, and then
    Horde.


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

    [2003-07-27 07:16:27] [email]stasphp.net[/email]

    What is the meaning of returning result of new by reference?

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

    [2003-07-09 04:12:56] jsemczyk at elv dot enic dot fr

    I have the same error, it seems like it comes from a function that must
    return a reference, but objects are already references.

    this doesn't work, but worked before beta1, I tried PEAR before beta1
    and it uses lots of this :

    function &myFunc()
    {
    return new MyClass();
    }

    This works fine :

    function myFunc()
    {
    return new MyClass();
    }

    I don't understand why it comes from return (new Class()); cause it
    doesn't work.

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

    [2003-07-03 07:09:44] karl at karlaustin dot com

    Well from the text of that item it would suggest that doing:

    return new object();

    is fine, but:

    return (new object());

    is not fine, that's how it would seem to me as an end user.

    PEAR is ridled with returns like the one I list (Although IMHO it
    should have only one return and assign return values to a variable then
    return at the end, but that's another story).

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

    [2003-07-03 06:17:54] [email]derickphp.net[/email]

    Cause:
    [url]http://news.php.net/article.php?group=php.zend-engine.cvs&article=1432[/url]

    I wonder if we really should break BC here...

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

    [2003-07-03 06:13:42] karl at karlaustin dot com

    Description:
    ------------
    Fatal error: Only variables or references can be returned by reference
    in /usr/local/php5/lib/php/DB/common.php on line 737

    If seems that doing:

    return new DB_result($this, $result);

    in a function results in the above error, but:

    $_tmp = new DB_result($this, $result);
    return $_tmp;

    Is fine.



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


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

    jsemczyk at elv dot enic dot fr Guest

Similar Threads

  1. Actionscript: Custom class function call problem
    By Aaron in forum Macromedia Flash
    Replies: 2
    Last Post: August 1st, 07:55 PM
  2. Returning a custom class in a Web Service
    By Iain in forum ASP.NET Web Services
    Replies: 3
    Last Post: July 5th, 10:06 AM
  3. Returning a custom class.....
    By Manni in forum ASP.NET Web Services
    Replies: 7
    Last Post: December 1st, 11:05 PM
  4. #24477 [Fbk->Bgs]: Problem returning new class by ref from function
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: July 29th, 10:58 AM
  5. Replies: 0
    Last Post: July 27th, 12:16 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