#33884 [Bgs]: "Only variable references should be returned by reference" if I return nothing

2005-07-29 Thread sniper
 ID:   33884
 Updated by:   [EMAIL PROTECTED]
 Reported By:  php-bug-33884 at ryandesign dot com
 Status:   Bogus
 Bug Type: Unknown/Other Function
 Operating System: N/A
 PHP Version:  4.4.0
 New Comment:

Hint: Try SEARCH to find the duplicate report..



Previous Comments:


[2005-07-29 21:46:22] [EMAIL PROTECTED]

Thank you for wasting my time (again).




[2005-07-29 19:09:08] php-bug-33884 at ryandesign dot com

I realize you must be very busy and that form responses let 
you handle bugs quicker, but I can't help but feel a little 
put off by them. I spent time analyzing a situation and 
writing it up in detail, only to have it shut down with no 
discussion by form responses. In particular, beginning your 
response with "Please do not submit the same bug more than 
once" makes it sound like I did so on purpose. (Your first 
response, which began "Thank you [...], but [...]" was 
better in this regard.) And especially in the case of 
duplicate bugs, it's essential that you let me know the 
other bug number, so that I can check and see whether it is 
truly the same bug. With the speed with which you must work 
through new bugs, I imagine some would get incorrectly 
classified; surely it's in your best interest to have us 
double-check for you.

I'm also not sure what I think about your deleting comments 
from this bug. You closed my bug as bogus, pasting in a form 
response that it is not a bug. I wrote a detailed reply 
further clarifying why I believe it is. You promptly deleted 
your original response and my reply, to replace it with 
another form response saying my bug is a duplicate, without 
saying what of. Might not my clarification have been helpful 
to the person who tries to solve the bug, whether or not it 
is a duplicate? Since I was not able to find the bug of 
which this one is a duplicate, might others not have the 
same difficulty, and might they not possibly benefit from 
having more-detailed information in this bug on which they 
could search?



[2005-07-29 19:08:44] php-bug-33884 at ryandesign dot com

I'm sorry, I was not aware that I had submitted a duplicate. I 
did search beforehand and was not able to find a similar bug. 
Since you seem to have found one, could you please tell me its 
bug number so I can have a look?



[2005-07-29 18:12:56] [EMAIL PROTECTED]

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.





[2005-07-27 15:02:41] php-bug-33884 at ryandesign dot com

Description:

Hi. After upgrading from PHP 4.3.11 to 4.4.0 I get the 
famous "Only variable references should be returned by 
reference" notice in one of my projects. The function in 
question returns by reference, but only needs to do this 
sometimes. Other times, it returns nothing at all, because 
the caller does not need a return value. In these latter 
cases, PHP produces the notice as of 4.4.0.

This surprised me because it's perfectly fine to have a 
normal return-by-copy function that does not return 
anything. So why not a return-by-reference function?

I couldn't find any documentation that if your function 
returns by reference, then you must always return something.

In my particular case I can rewrite the function so that it 
always returns something, even when the caller has no use 
for it. I just wasn't sure if the notice in this case was 
intended, and if so, why.

If the behavior is intended, then the documentation should 
reflect this.

Reproduce code:
---
error_reporting(E_ALL);

function &foo_by_reference_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function &foo_by_reference_without_return() {
echo __FUNCTION__ . "\n";
} // line 11
function foo_by_copy_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function foo_by_copy_without_return() {
echo __FUNCTION__ . "\n";
}

foo_by_reference_with_return();
foo_by_reference_without_return(); // causes notice in 4.4.0
foo_by_copy_with_return();
foo_by_copy_without_return();

Expected result:

foo_by_reference_with_return
foo_by_reference_without_return
foo_by_copy_with_return
foo_by_copy_without_return

Actual result:
--
foo_by_reference_with_return
foo_by_reference_without_return
Notice: Only variable references should be returned by 
reference in references.php on line 11
foo_by_copy_with_return
foo_by_copy_without_return


#33884 [Bgs]: "Only variable references should be returned by reference" if I return nothing

2005-07-29 Thread php-bug-33884 at ryandesign dot com
 ID:   33884
 User updated by:  php-bug-33884 at ryandesign dot com
 Reported By:  php-bug-33884 at ryandesign dot com
 Status:   Bogus
 Bug Type: Unknown/Other Function
 Operating System: N/A
 PHP Version:  4.4.0
 New Comment:

I'm sorry, I was not aware that I had submitted a duplicate. I 
did search beforehand and was not able to find a similar bug. 
Since you seem to have found one, could you please tell me its 
bug number so I can have a look?


Previous Comments:


[2005-07-29 18:12:56] [EMAIL PROTECTED]

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.





[2005-07-27 15:02:41] php-bug-33884 at ryandesign dot com

Description:

Hi. After upgrading from PHP 4.3.11 to 4.4.0 I get the 
famous "Only variable references should be returned by 
reference" notice in one of my projects. The function in 
question returns by reference, but only needs to do this 
sometimes. Other times, it returns nothing at all, because 
the caller does not need a return value. In these latter 
cases, PHP produces the notice as of 4.4.0.

This surprised me because it's perfectly fine to have a 
normal return-by-copy function that does not return 
anything. So why not a return-by-reference function?

I couldn't find any documentation that if your function 
returns by reference, then you must always return something.

In my particular case I can rewrite the function so that it 
always returns something, even when the caller has no use 
for it. I just wasn't sure if the notice in this case was 
intended, and if so, why.

If the behavior is intended, then the documentation should 
reflect this.

Reproduce code:
---
error_reporting(E_ALL);

function &foo_by_reference_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function &foo_by_reference_without_return() {
echo __FUNCTION__ . "\n";
} // line 11
function foo_by_copy_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function foo_by_copy_without_return() {
echo __FUNCTION__ . "\n";
}

foo_by_reference_with_return();
foo_by_reference_without_return(); // causes notice in 4.4.0
foo_by_copy_with_return();
foo_by_copy_without_return();

Expected result:

foo_by_reference_with_return
foo_by_reference_without_return
foo_by_copy_with_return
foo_by_copy_without_return

Actual result:
--
foo_by_reference_with_return
foo_by_reference_without_return
Notice: Only variable references should be returned by 
reference in references.php on line 11
foo_by_copy_with_return
foo_by_copy_without_return





-- 
Edit this bug report at http://bugs.php.net/?id=33884&edit=1


#33884 [Bgs]: "Only variable references should be returned by reference" if I return nothing

2005-07-27 Thread php-bug-33884 at ryandesign dot com
 ID:   33884
 User updated by:  php-bug-33884 at ryandesign dot com
-Reported By:  php-bugs-2005 at ryandesign dot com
+Reported By:  php-bug-33884 at ryandesign dot com
 Status:   Bogus
 Bug Type: Unknown/Other Function
 Operating System: N/A
 PHP Version:  4.4.0
 New Comment:

Thank you for your response.

I already checked the documentation on functions returning 
by reference and could not find any indication that such 
functions must always return something. If this is the case, 
then this should be documented. If it already is documented, 
I would appreciate a direct link to the relevant page.

I have many years of experience in software development, 
software testing and bug reporting, and did not think my bug 
report had been filed improperly. If you have specific 
suggestions for how I could make future bug reports more 
useful to you, by all means please share them with me.

Truly, if my function never returned anything, then as you 
say I would not need to declare the it as return-by-
reference. However, I do sometimes need to return a 
reference. Therefore the function must be declared in this 
way. Here is a more concrete example of what my function 
does:

class foo {
function &get_or_set($bar, $baz = null) {
if ($baz) {
$GLOBALS['qux'][$bar] =& $baz;
} else {
return $GLOBALS['qux'][$bar];
}
}
}

In this particular case, I can avoid the error by modifying 
the code so that the "else" part occurs unconditionally. I 
just couldn't see any reason to require that a return-by-
reference function must return a value, when return-by-copy 
functions are not restricted in this manner. If such a 
reason exists, please enlighten me.


Previous Comments:


[2005-07-27 16:14:27] [EMAIL PROTECTED]

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

If you don\'t return anything you don\'t need 
return-by-reference... 



[2005-07-27 15:02:41] php-bug-33884 at ryandesign dot com

Description:

Hi. After upgrading from PHP 4.3.11 to 4.4.0 I get the 
famous "Only variable references should be returned by 
reference" notice in one of my projects. The function in 
question returns by reference, but only needs to do this 
sometimes. Other times, it returns nothing at all, because 
the caller does not need a return value. In these latter 
cases, PHP produces the notice as of 4.4.0.

This surprised me because it's perfectly fine to have a 
normal return-by-copy function that does not return 
anything. So why not a return-by-reference function?

I couldn't find any documentation that if your function 
returns by reference, then you must always return something.

In my particular case I can rewrite the function so that it 
always returns something, even when the caller has no use 
for it. I just wasn't sure if the notice in this case was 
intended, and if so, why.

If the behavior is intended, then the documentation should 
reflect this.

Reproduce code:
---
error_reporting(E_ALL);

function &foo_by_reference_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function &foo_by_reference_without_return() {
echo __FUNCTION__ . "\n";
} // line 11
function foo_by_copy_with_return() {
echo __FUNCTION__ . "\n";
return $GLOBALS['bar'];
}
function foo_by_copy_without_return() {
echo __FUNCTION__ . "\n";
}

foo_by_reference_with_return();
foo_by_reference_without_return(); // causes notice in 4.4.0
foo_by_copy_with_return();
foo_by_copy_without_return();

Expected result:

foo_by_reference_with_return
foo_by_reference_without_return
foo_by_copy_with_return
foo_by_copy_without_return

Actual result:
--
foo_by_reference_with_return
foo_by_reference_without_return
Notice: Only variable references should be returned by 
reference in references.php on line 11
foo_by_copy_with_return
foo_by_copy_without_return





-- 
Edit this bug report at http://bugs.php.net/?id=33884&edit=1