List Info

Thread: Re: Difference between isset() and empty() .




Re: Difference between isset() and empty() .
country flaguser name
United States
2007-05-21 07:37:59

--- In in-phpug%40yahoogroups.com">in-phpugyahoogroups.com, "Dr. Tarique Sani" <tarique...> wrote:
&gt;
> Shadab Wadiwala wrote:
&gt; > Hi !!
> >
>; > I want to know what's the difference between the functions
----
&gt; > isset() and empty()
> >
> Start by running the code below
&gt; <?php
> error_reporting(E_ALL);
>
> echo isset($something);
> echo empty($something);
>
> ?>
&gt;
> and let us know if you figure it out
>
> Cheers
&gt; Tarique
>
> --
> =============================================================
> PHP Applications for E-Biz: http://www.sanisoft.com
>
> Coppermine Picture Gallery: http://coppermine.sf.net
>; =============================================================
>
This is Difference between isset() and empty()
isset() isset()
determines whether a certain variable has already
been declared by PHP. It returns a boolean value
true if the variable has already been set, and
false otherwise, or if the variable is set to the value
NULL .
Consider the following script:
if (isset($first_name)) {
print '$first_name is set';
}
This code snippet checks whether the variable
$first_name
is defined. If
$first_name
is defined,
isset()
returns
true
, which will display '
$first_name is
set.
' If it isn't, no output is generated.
isset()
can also be used on array elements (discussed in a later section)
and object properties. Here are examples for the relevant syntax,
which you can refer to later:
&amp;#9758;
Checking an array element:
if (isset($arr["offset"])) {
...
}
&#9758;
Checking an object property:
if (isset($obj->property)) {
...
}
Note that in both examples, we didn't check if
$arr
or
$obj
are set (before
we checked the offset or property, respectively). The
isset()
construct returns
false
automatically if they are not set.
isset()
is the only one of the three language constructs that accepts an
arbitrary amount of parameters. Its accurate prototype is as follows:
isset($var1, $var2, $var3, ...);
It only returns
true
if all the variables have been defined; otherwise, it
returns
false
. This is useful when you want to check if the required input variables
for your script have really been sent by the client, saving you a
series of single isset()checks.

empty()
empty() empty() may be used to check if a variable has not been
declared or its value is false. This language construct is usually
used to check
if a form variable has not been sent or does not contain data. When
checking a
variable's truth value, its value is first converted to a Boolean
according to the
rules in the following section, and then it is checked for true/false.
For example:
if (empty($name)) {
print 'Error: Forgot to specify a value for $name';
}
This code prints an error message if $name doesn't contain a value that
evaluates to true.
Cheer Up
Illahi Bux

__._,_.___
.

__,_._,___
Re: Re: Difference between isset() and empty() .
country flaguser name
India
2007-06-01 23:24:11

Dear Sir
I want to know how to and where and how it works
error_reporting( E_ALL).

regards
R.Sumathi

--- UNAR < unar2002%40yahoo.com">unar2002yahoo.com> wrote:

> --- In in-phpug%40yahoogroups.com">in-phpugyahoogroups.com, "Dr. Tarique Sani"
> <tarique...> wrote:
&gt; >
>; > Shadab Wadiwala wrote:
&gt; > > Hi !!
> > >
>; > > I want to know what's the difference
> between the functions
> ----
>; > > isset() and empty()
> > >
> > Start by running the code below
&gt; > <?php
> > error_reporting(E_ALL);
> >
> > echo isset($something);
> > echo empty($something);
> >
> > ?>
&gt; >
> > and let us know if you figure it out
> >
> > Cheers
&gt; > Tarique
> >
> > --
> >
>;
=============================================================
>; > PHP Applications for E-Biz:
&gt; http://www.sanisoft.com
> >
> > Coppermine Picture Gallery:
> http://coppermine.sf.net
>; >
>;
=============================================================
>; >
>; This is Difference between isset() and empty()
> isset() isset()
> determines whether a certain variable has already
> been declared by PHP. It returns a boolean value
&gt; true if the variable has already been set, and
> false otherwise, or if the variable is set to the
> value
&gt; NULL .
> Consider the following script:
> if (isset($first_name)) {
> print '$first_name is set';
&gt; }
> This code snippet checks whether the variable
> $first_name
> is defined. If
> $first_name
> is defined,
> isset()
> returns
> true
>; , which will display '
> $first_name is
> set.
>; ' If it isn't, no output is generated.
> isset()
> can also be used on array elements (discussed in a
> later section)
> and object properties. Here are examples for the
> relevant syntax,
> which you can refer to later:
&gt; &#9758;
> Checking an array element:
> if (isset($arr["offset"])) {
> ...
> }
> &#9758;
> Checking an object property:
> if (isset($obj->property)) {
> ...
> }
> Note that in both examples, we didn't check if
> $arr
>; or
> $obj
>; are set (before
> we checked the offset or property, respectively).
>; The
> isset()
> construct returns
> false
&gt; automatically if they are not set.
>; isset()
> is the only one of the three language constructs
> that accepts an
> arbitrary amount of parameters. Its accurate
> prototype is as follows:
> isset($var1, $var2, $var3, ...);
&gt; It only returns
> true
>; if all the variables have been defined; otherwise,
> it
> returns
> false
&gt; . This is useful when you want to check if the
> required input variables
> for your script have really been sent by the client,
> saving you a
> series of single isset()checks.
>
> empty()
> empty() empty() may be used to check if a variable
> has not been
>; declared or its value is false. This language
> construct is usually
> used to check
&gt; if a form variable has not been sent or does not
> contain data. When
>; checking a
> variable's truth value, its value is first converted
> to a Boolean
> according to the
> rules in the following section, and then it is
> checked for true/false.
> For example:
> if (empty($name)) {
> print 'Error: Forgot to specify a value for $name';
> }
> This code prints an error message if $name doesn't
> contain a value that
>; evaluates to true.
&gt; Cheer Up
> Illahi Bux
>
>

Did you know? You can CHAT without downloading messenger. Click here http://in.messenger.yahoo.com/webmessengerpromo.php

__._,_.___
.

__,_._,___
Re: Re: Difference between isset() and empty() .
country flaguser name
United States
2007-06-02 00:11:35

Dear Sumathi,

When the code encounter errors it throws the error message to the output
screen. Errors can be of various types, like notice, warning and ERROR, some
are critical and some can be ignored (but it is advisable to take care of
all errors but some open source application are difficult to run with E_ALL,
thats is showing all errors).

error_reporting(E_ALL ^ E_NOTICE); means show all errors except notices.
When we run alpha,beta and production servers, we have

error_reporting(0); for production as we do not want to show any error to
the user but we catch it and send it to our programmers.

error_reporting(E_ALL ^ E_NOTICE); for beta
error_reporting(E_ALL) for alpha so that we can take care of all the errors.
As I said sometimes it is not possible for open source (third party
applications) as fixing these errors will create more problems with next
updates.

Thanks,
Aji Issac
--
http://www.idealwebtools.com/blog/top/ - know your *nix server better with
top command. This will help you understand more about its performance.

On 6/2/07, R Sumathi < sumathi80in%40yahoo.co.in">sumathi80inyahoo.co.in> wrote:
&gt;
> Dear Sir
> I want to know how to and where and how it works
&gt; error_reporting( E_ALL).
>
> regards
> R.Sumathi
>
&gt;
> --- UNAR < unar2002%40yahoo.com">unar2002yahoo.com <unar2002%40yahoo.com>>; wrote:
&gt;
> > --- In in-phpug%40yahoogroups.com">in-phpugyahoogroups.com <in-phpug%40yahoogroups.com&gt;, "Dr.
> Tarique Sani"
> > <tarique...> wrote:
&gt; > >
>; > > Shadab Wadiwala wrote:
&gt; > > > Hi !!
> > > >
>; > > > I want to know what's the difference
> > between the functions
> > ----
>; > > > isset() and empty()
> > > >
>; > > Start by running the code below
&gt; > > <?php
> > > error_reporting(E_ALL);
> > >
>; > > echo isset($something);
> > > echo empty($something);
> > >
>; > > ?>
&gt; > >
>; > > and let us know if you figure it out
> > >
>; > > Cheers
&gt; > > Tarique
> > >
>; > > --
> > >
>; >
>; =============================================================
> > > PHP Applications for E-Biz:
&gt; > http://www.sanisoft.com
> > >
>; > > Coppermine Picture Gallery:
> > http://coppermine.sf.net
>; > >
>; >
>; =============================================================
> > >
>; > This is Difference between isset() and empty()
> > isset() isset()
> > determines whether a certain variable has already
> > been declared by PHP. It returns a boolean value
&gt; > true if the variable has already been set, and
> > false otherwise, or if the variable is set to the
> > value
&gt; > NULL .
> > Consider the following script:
> > if (isset($first_name)) {
> > print '$first_name is set';
&gt; > }
> > This code snippet checks whether the variable
> > $first_name
> > is defined. If
> > $first_name
> > is defined,
> > isset()
> > returns
> > true
>; > , which will display '
> > $first_name is
> > set.
>; > ' If it isn't, no output is generated.
> > isset()
> > can also be used on array elements (discussed in a
> > later section)
> > and object properties. Here are examples for the
> > relevant syntax,
> > which you can refer to later:
&gt; > &#9758;
> > Checking an array element:
> > if (isset($arr["offset"])) {
> > ...
> > }
> > &#9758;
> > Checking an object property:
> > if (isset($obj->property)) {
> > ...
> > }
> > Note that in both examples, we didn't check if
> > $arr
>; > or
> > $obj
>; > are set (before
> > we checked the offset or property, respectively).
>; > The
> > isset()
> > construct returns
> > false
&gt; > automatically if they are not set.
>; > isset()
> > is the only one of the three language constructs
> > that accepts an
> > arbitrary amount of parameters. Its accurate
> > prototype is as follows:
> > isset($var1, $var2, $var3, ...);
&gt; > It only returns
> > true
>; > if all the variables have been defined; otherwise,
> > it
> > returns
> > false
&gt; > . This is useful when you want to check if the
> > required input variables
> > for your script have really been sent by the client,
> > saving you a
> > series of single isset()checks.
> >
>; > empty()
> > empty() empty() may be used to check if a variable
> > has not been
>; > declared or its value is false. This language
> > construct is usually
> > used to check
&gt; > if a form variable has not been sent or does not
> > contain data. When
>; > checking a
> > variable's truth value, its value is first converted
> > to a Boolean
> > according to the
> > rules in the following section, and then it is
> > checked for true/false.
> > For example:
> > if (empty($name)) {
> > print 'Error: Forgot to specify a value for $name';
> > }
> > This code prints an error message if $name doesn't
> > contain a value that
>; > evaluates to true.
&gt; > Cheer Up
> > Illahi Bux
> >
>; >
>;
> Did you know? You can CHAT without downloading messenger. Click here
>; http://in.messenger.yahoo.com/webmessengerpromo.php
>
>
>

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )