#48937 [Com]: Strict standards: Only variables should be passed by reference
| From: | software at whatsonyourbrain dot com | Date: | Thu, 16 Jul 2009 14:35:23 +0000 |
| Subject: | #48937 [Com]: Strict standards: Only variables should be passed by reference | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2499@lists.php.net to get a copy of this message | ||
ID: 48937
Comment by: software at whatsonyourbrain dot com
Reported By: software at whatsonyourbrain dot com
Status: Open
Bug Type: Documentation problem
Operating System: Win XP SP3
PHP Version: 5.3.0
New Comment:
right. But the reader needs to understand why. The answer: Because,
only VARIABLES may be passed by reference, as the error clearly states.
What is missing here-- for the benefit of others relying upon The
Manual for a proper reference-- is a deeper explanation of the reason
this error occurs. This is a PHP "type juggling" issue [
http://php.net/manual/de/language.types.type-juggling.php
]
REASON FOR ERROR:
end() is able to extrapolate what TYPE CAST is passed to it, based on
the context of the procedure (e.g. a Variable, or an Array). The problem
here arises due to passing-by-reference loosely-typed data. To process
loosely-typed data w/out error in this instance-- because the data in
end() [and other built-in-functions] is Passed-By-Reference, the TYPE
must NOT be an ARRAY, but a VARIABLE. Although previous versions of PHP
were processing data no matter how the TYPE was CAST, this is no longer
the case. When considering what to pass to "end()", no longer may the
programmer disregard that data type (i.e. It is important to know when
TYPE CASTING data, whether the type cast is an Array, String, Binary,
Float, etc., and ALSO precisely HOW a function will handle the data it
is passed)
SPECIFICALLY:
In this example, "explode()" returns data of type Array. Versions of
PHP pervious to __(?)__ would process data passed to end(), regardless
of its TYPE, without error. Since PHP version __?__, Strict Standards
require that only Variables are passed by reference. To pass data to end
using explode() is incompatible in this instance, due to the TYPE
CASTING of explode() as Array. This explains the use of a /temporary/
variable, $parts, in the example provided [@16 Jul 1:42pm UTC].
Previous Comments:
------------------------------------------------------------------------
[2009-07-16 13:42:32] rasmus@php.net
Not at all, simply do:
$parts = explode('/',$item);
$itemsArray[]= end($parts);
If you want to use end() in this case.
------------------------------------------------------------------------
[2009-07-16 13:36:50] software at whatsonyourbrain dot com
What is the proper way of coding with end(), for strict standards-- so
that its use is not erroneous?
It would seem the instructions provided [@16 Jul 2:56am UTC] are
directing the user to avoid use of "end()". Should I assume that "end()"
itself will be deprecated?
------------------------------------------------------------------------
[2009-07-16 02:56:22] rasmus@php.net
Converting to an array doesn't make much sense here. You are just
doing simple string stuff. I would change it to:
$itemsArray[]= substr(strrchr($item,'/'),1);
------------------------------------------------------------------------
[2009-07-16 01:59:05] software at whatsonyourbrain dot com
please advise [@16 Jul 12:56am].
(i.e. what is the proper way of coding this procedure, or-- what is the
proper way of coding this procedure to avoid error?)
------------------------------------------------------------------------
[2009-07-16 00:58:09] rasmus@php.net
I guess we can leave it open as a documentation problem instead.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/48937
--
Edit this bug report at http://bugs.php.net/?id=48937&edit=1