473,378 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
6 18969
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jonas | last post by:
Dear members, How can I use a function return value in a regexpr? $tmp=~s/mysearch/myfunction($1)/; sub myfunction { return $v; }
1
by: Tropos | last post by:
Query: Will a MutexGuard object release before a function return value is copied? Consider the C++ code: class MutexGuard //A familiar sort of class for making mutexes exception-safe { . ....
7
by: Michael Klatt | last post by:
class Foo { public : explicit Foo(int i) : m_int(i) {} private : int m_int; }; Foo f(int i)
4
by: wongjoekmeu | last post by:
Hello All, I know that when you pass an argument to a function (if you want let the function be able to change the value) then you can choose to pass the argument by reference or a pointer to...
4
by: bluedolphin | last post by:
This is my first function in Visual and I'm having a simple syntax syntax issue that I'm hoping someone can help correct for me. I have a function Public Function...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
4
by: pradeep | last post by:
Hello friends ~ We know that a C function will return a 32-bit value from a function in %eax and a 64-bit value in %edx:%eax. But what about larger return types, for example large structs? The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.