472,986 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

'Parse error' problem in "isset" and "empty"

I've been having some problems with a parse error that I can't figure
out (PHP 4.3.11 on Solaris9). Sample code:

<?php
// getting strange parse errors on this
class A {
var $value;
function A() {
$this->value = 1;
}

function getValue() {
return $this->value;
}
}

$a = new A();
if (!empty($a->getValue())) {
echo "success";
}
else {
echo "failure";
}
?>

The result of this is:

Parse error: parse error, unexpected '(', expecting ')' in
/foo/public_html/parse_errors.php on line 15

I also get the same effect with "isset", however, testing with "is_null"
or "is_int" produces the correct ("success"/"failure") result. Any ideas?

/Marcin
Aug 21 '05 #1
4 2617
Check out the following:

http://www.php.net/manual/en/function.empty.php

empty() and isset() only work on variables. In your case,
$a->getValue() is the return value of a function -- not a variable.
You could do something like:

$a = new A();
$v = $a->getValue();
if (!empty($v)) {
echo "success";
}
else {
echo "failure";
}

Alternatively, you could define your own isEmpty() function which does
whatever you want. It could be as simple as:

function isEmpty($value) {
return (strlen($value) == 0);
}

Also, as of PHP 5.1 you can overload calls to empty() and isset() on
object properties. Most useful when you also overload the getters and
settings (via __get() and __set()).

Aug 22 '05 #2
ZeldorBlat wrote:
Check out the following:

http://www.php.net/manual/en/function.empty.php

empty() and isset() only work on variables. In your case,
$a->getValue() is the return value of a function -- not a variable.
You could do something like:
Yea, thanks. I noticed this just as I posted the article, and then
promply canceled it, but it seems it didn't get canceled everywhere.
the is_int and is_null work differently, and it threw me off a bit.
$a = new A();
$v = $a->getValue();
if (!empty($v)) {
echo "success";
}
else {
echo "failure";
}
Yes, that's how I do it now. A bit of fuss, but works.
Alternatively, you could define your own isEmpty() function which does
whatever you want. It could be as simple as:

function isEmpty($value) {
return (strlen($value) == 0);
}
Yes, but again, "empty" checks for null, 0, etc. Which is useful.
Also, as of PHP 5.1 you can overload calls to empty() and isset() on
object properties. Most useful when you also overload the getters and
settings (via __get() and __set()).


Will have a lookie, but still working in 4.x level (and it's not
going to change anytime soon). Thanks.

/Marcin
Aug 22 '05 #3
Well, that's the beauty of writing your own isEmpty()...you can have it
do whatever you want. You could simulate PHP's empty() behavior pretty
easily:

function isEmpty($value) {
return (strlen($value) == 0 || is_null($value) || $value == 0);
}

Aug 22 '05 #4
Hello!
Well, that's the beauty of writing your own isEmpty()...you can have it
do whatever you want. You could simulate PHP's empty() behavior pretty
easily:

function isEmpty($value) {
return (strlen($value) == 0 || is_null($value) || $value == 0);
}


If you want to emulate PHP empty()'s behaviour completely (and only
then) you should use

function isEmpty($value) {
return empty($value);
}

I assume this is faster than doing the checks yourself.

Greetings,
Hero
Aug 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
0
by: newbie_mw | last post by:
Hi Ian, Thanks for help! The columns and variables are exactly matched so it shouldn't be the problem. Actually the original html and php files are pretty long. But I guess a more detailed...
1
by: newbie_mw | last post by:
Seems my post was buried in more cries for help :-) I will try again. It's probably a very novice question so please take a look! Thanks!...
32
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at...
1
by: Westcoast Sheri | last post by:
When "register globals" is set to "on," has anyone noticed if PHP Version 5 affects the usage of "isset" or not? For example, in a webpage form, should the following code: if...
1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
2
by: Bob Stearns | last post by:
I thought that the given expression was always TRUE if "not_there" wasn't among the keys (or subscripts if you will) of $_SESSION. Below find a dump of $_SESSION, a small snippet of code and the...
7
by: Anette | last post by:
Hi, I'm very new at PHP. I've tried for a long time now to get a page that has a form in a certain way: 1. When form is submitted the data in a table should be writted on the same page. 2....
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.