By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,689 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,689 IT Pros & Developers. It's quick & easy.

Can't use function return value in write context--huh?

P: n/a
Can someone explain why this line
$bool = isset($_POST['email']) && !empty(trim($_POST['email']));
causes the error message "Can't use function return value in write
context". trim() returns a string. I test if it is empty. So what is
wrong with that?
Jul 25 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ku**************@gmail.com schrieb:
Can someone explain why this line
$bool = isset($_POST['email']) && !empty(trim($_POST['email']));
causes the error message "Can't use function return value in write
context". trim() returns a string. I test if it is empty. So what is
wrong with that?
The functions empty() *only* tests Variables.
All other wil cause an error.

Jul 25 '08 #2

P: n/a
On Jul 25, 1:39*pm, kurt.krueckeb...@gmail.com wrote:
Can someone explain why this line
$bool = isset($_POST['email']) && !empty(trim($_POST['email']));
causes the error message "Can't use function return value in write
context". trim() returns a string. I test if it is empty. So what is
wrong with that?
not that speed matters but && $_POST['email'] != '' is how I would do
it.

As mentioned above and to quote from php.net "Note: empty() only
checks variables as anything else will result in a parse error. In
other words, the following will not work: empty(trim($name)). "

What I said above is faster than

$email = trim($_POST['email'];

if (... && !empty($email)
Jul 25 '08 #3

P: n/a
On Jul 25, 10:39 am, kurt.krueckeb...@gmail.com wrote:
Can someone explain why this line
$bool = isset($_POST['email']) && !empty(trim($_POST['email']));
causes the error message "Can't use function return value in write
context". trim() returns a string. I test if it is empty. So what is
wrong with that?)
Your function would fail if 'email' isn't set.

try this:

$bool = !empty( ( isset( $_POST['eamil'] ) ? trim( $_POST['email'] ) :
'' ) );
Jul 25 '08 #4

P: n/a
la***@portcommodore.com wrote:
On Jul 25, 10:39 am, kurt.krueckeb...@gmail.com wrote:
>Can someone explain why this line
$bool = isset($_POST['email']) && !empty(trim($_POST['email']));
causes the error message "Can't use function return value in write
context". trim() returns a string. I test if it is empty. So what is
wrong with that?)

Your function would fail if 'email' isn't set.

try this:

$bool = !empty( ( isset( $_POST['eamil'] ) ? trim( $_POST['email'] ) :
'' ) );
Incorrect. That's what isset() tests. If $_POST['email'] is not set,
the rest of the expression is never evaluated.

The others had it correct - empty() only works on variables, not the
results of an expression.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 26 '08 #5

P: n/a
Incorrect. That's what isset() tests. If $_POST['email'] is not set,
the rest of the expression is never evaluated.

The others had it correct - empty() only works on variables, not the
results of an expression.
Thanks for mentioning that "If $_POST['email'] is not set, the rest of
the expression is never evaluated." That is why I did
isset( $_POST['eamil']) first.
Jul 26 '08 #6

P: n/a
kkruecke wrote:
>Incorrect. That's what isset() tests. If $_POST['email'] is not set,
the rest of the expression is never evaluated.

The others had it correct - empty() only works on variables, not the
results of an expression.

Thanks for mentioning that "If $_POST['email'] is not set, the rest of
the expression is never evaluated." That is why I did
isset( $_POST['eamil']) first.
Yep, and that is the correct way to do it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.