473,396 Members | 1,895 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,396 software developers and data experts.

Can't use function return value in write context

Claus Mygind
571 512MB
I want to test a value of a column to see if it is null, empty or just contains blanks spaces.

And I get the error stated in the title of this thread, when I just want to test the trimmed value like so:
Expand|Select|Wrap|Line Numbers
  1. if ( empty(trim($val)) ) {
  2.  
So I it seems I am forced to add a second line to my code like this
Expand|Select|Wrap|Line Numbers
  1. $val = trim($val);
  2. if ( empty( $val ) ) {
  3.  
What I don't understand is I can use it in a "switch" command as this code works fine for me.

Expand|Select|Wrap|Line Numbers
  1. switch (strlen(trim($val)))
  2. {
  3.  
So here I basically have two "if" commands one where the "trim" function works and one where it does not work.

Is this true? And if so Why?
Mar 21 '11 #1

✓ answered by Dormilich

empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).
found in the manual.

besides that, switch() is not a function (not that empty() were a function either …).

3 2162
Dormilich
8,658 Expert Mod 8TB
empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).
found in the manual.

besides that, switch() is not a function (not that empty() were a function either …).
Mar 21 '11 #2
Claus Mygind
571 512MB
Thanks for the reply and clarification. Of course I was working on a variable "$val"

How disappointing to see this limitation as opposed to the more flexible use of empty() in dBase.

Sorry for stating that empty() was a function, I guess I just thought anything that ended with () was a function. Live and lean.
Mar 21 '11 #3
Dormilich
8,658 Expert Mod 8TB
there are even more language constructs that look like a function (include(), require(), echo(), print()).

PS. to be honest, I also looked it up.
Mar 21 '11 #4

Sign in to post your reply or Sign up for a free account.

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; }
2
by: Michael Klatt | last post by:
I have a resource handle class (call it ResourceHandle) that works like std::auto_ptr to automatically manage resource pointers from a C API (call them T*): class ResourceHandle { public :...
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...
9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
5
by: Ghislain Tanguay | last post by:
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a string or anything else I use a function. It's more verbose. In my new...
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"...
6
by: kurt.krueckeberg | last post by:
Can someone explain why this line $bool = isset($_POST) && !empty(trim($_POST)); causes the error message "Can't use function return value in write context". trim() returns a string. I test if it...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.