Skip to main content
Inspiring
October 9, 2006
Question

Somethign between unset() and empty() (kinda)

  • October 9, 2006
  • 9 replies
  • 399 views
If now empty() checks to see if a variable has something in it, what can I
use to just empty a variable, or am I even causing any needed work when I
use unset()?

--

TIA,

Jon Parkhurst
PriivaWeb
http://priiva.net.


This topic has been closed for replies.

9 replies

Inspiring
October 17, 2006
gads, but i've been out of school too long. i should have used print, not
echo.

<hangs head>

"Crash" <crash@cdcdigitalBLAG.com> wrote in message
news:eh31pm$oii$1@forums.macromedia.com...
> What I was doing was this:
>
> Before (& now) I had somethign like this:
> fucntion create_picture($l:link from database (to pic), $m:pic size){
> $l='<img src="image_generator.php?img='.$l.'sz='.$m.'">';
> return $l
> }
>
> $picture=create_picture($l, $m);
> echo $picture;
>
> What I tried to do was simple remove the return and place the echo inside
> the function.
>
> What hapened was :
>
> External Echo:
> good picture, result: image.php?img=Whatever.jpg&sz=thumb
>
> Inside Echo:
> no picture, result: image.php?img=Whatever.jpg&sz=thumb
>
> When I echoed inside the function, it looks like my encapsulation was
shot.
> My image would not produce b/c my php was not picking up on the second
> variable.
>
>
>


Inspiring
October 17, 2006
What I was doing was this:

Before (& now) I had somethign like this:
fucntion create_picture($l:link from database (to pic), $m:pic size){
$l='<img src="image_generator.php?img='.$l.'sz='.$m.'">';
return $l
}

$picture=create_picture($l, $m);
echo $picture;

What I tried to do was simple remove the return and place the echo inside
the function.

What hapened was :

External Echo:
good picture, result: image.php?img=Whatever.jpg&sz=thumb

Inside Echo:
no picture, result: image.php?img=Whatever.jpg&sz=thumb

When I echoed inside the function, it looks like my encapsulation was shot.
My image would not produce b/c my php was not picking up on the second
variable.



Inspiring
October 17, 2006
crash wrote:
> Can you tell me either what to look for, or why a value is different if
> echo'd from a function rather than returned from a function?

They should be the same, as long as you assign the value returned from
the function to a variable.

> I can't remember what the term is to look for.

You're probably thinking about variable scope. The value of variables
inside a function are limited in scope to inside the function. The only
exceptions are when the value is passed by reference or when the global
keyword is used inside the function.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
October 17, 2006
David,

Can you tell me either what to look for, or why a value is different if
echo'd from a function rather than returned from a function?

I can't remember what the term is to look for.

I'm sure i'll find it somewhere today.

Jon

"David Powers" <david@example.com> wrote in message
news:egp2p1$21s$1@forums.macromedia.com...
> crash wrote:
>> Is there a difference between $var='' and $var=""?
>
> No.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
October 13, 2006
crash wrote:
> Is there a difference between $var='' and $var=""?

No.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
October 13, 2006
Thanks guys, I missed marking this and thus missed the response.

I don't know why, I was just expecting a "set0val" or some such thing.

Is there a difference between $var='' and $var=""?


"crash" <crash@bcdcdigital.com> wrote in message
news:egeei3$pqm$1@forums.macromedia.com...
> If now empty() checks to see if a variable has something in it, what can I
> use to just empty a variable, or am I even causing any needed work when I
> use unset()?
>
> --
>
> TIA,
>
> Jon Parkhurst
> PriivaWeb
> http://priiva.net.
>


Inspiring
October 10, 2006
got it, thanks David

--

Dave Buchholz
I-CRE8
www.i-cre8.co.uk
Skype ID: I-CRE8


"David Powers" <david@example.com> wrote in message
news:egeje4$1vm$1@forums.macromedia.com...
Dave Buchholz wrote:
> $variable_name = "" or am I missing something ?

$variable_name = '' sets the variable to an empty string.

unset($variable_name) removes the variable completely.

$var = 5;
echo $var.'<br />'; // displays 5
$var = '';
if (empty($var)) {
echo '$var contains no value<br />'; // <-- This will be displayed
}
unset($var);
if (isset($var)) {
echo '$var still exists<br />'; // <-- This won't be displayed
}
else {
echo '$var does not exist'; // <-- This will
}

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/


Inspiring
October 9, 2006
Dave Buchholz wrote:
> $variable_name = "" or am I missing something ?

$variable_name = '' sets the variable to an empty string.

unset($variable_name) removes the variable completely.

$var = 5;
echo $var.'<br />'; // displays 5
$var = '';
if (empty($var)) {
echo '$var contains no value<br />'; // <-- This will be displayed
}
unset($var);
if (isset($var)) {
echo '$var still exists<br />'; // <-- This won't be displayed
}
else {
echo '$var does not exist'; // <-- This will
}

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
October 9, 2006
$variable_name = "" or am I missing something ?

--

Dave Buchholz
I-CRE8
www.i-cre8.co.uk
Skype ID: I-CRE8


"crash" <crash@bcdcdigital.com> wrote in message
news:egeei3$pqm$1@forums.macromedia.com...
If now empty() checks to see if a variable has something in it, what can I
use to just empty a variable, or am I even causing any needed work when I
use unset()?

--

TIA,

Jon Parkhurst
PriivaWeb
http://priiva.net.