php-general Digest 6 Mar 2011 19:16:17 -0000 Issue 7214

Topics (messages 311710 through 311717):

$$var
        311710 by: Ashim Kapoor
        311712 by: Russell Dias
        311713 by: Ashim Kapoor
        311715 by: shiplu
        311716 by: sexyprout
        311717 by: Jonesy

imap_search ?
        311711 by: Tontonq Tontonq

Re: $GLOBALS example script on php.net
        311714 by: Ashim Kapoor

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Dear All,

I was reading the php manual for session_register, and I found the following
line there : -


$_SESSION[$var] = $$var;

Why do I need $$ there ? Can someone explain?

Thank you,
Ashim

--- End Message ---
--- Begin Message ---
Hi Ashim,

These are called Variable Variables. Ideally they should be avoided,
as they introduce unnecessary legibility issues.

This is what it does in a nutshell, it's actually quite simple:

$foo = 'bar';
$bar = 'foobar';
echo $$foo;    //This prints foobar

What it does is, take the value of $foo (which is 'bar') and if a
variable exists by that name, it will go forth and print the value of
$bar; In this case foobar.
On Sun, Mar 6, 2011 at 11:12 PM, Ashim Kapoor <[email protected]> wrote:
> Dear All,
>
> I was reading the php manual for session_register, and I found the following
> line there : -
>
>
> $_SESSION[$var] = $$var;
>
> Why do I need $$ there ? Can someone explain?
>
> Thank you,
> Ashim
>

--- End Message ---
--- Begin Message ---
> Hi Ashim,
>
> These are called Variable Variables. Ideally they should be avoided,
> as they introduce unnecessary legibility issues.
>
> This is what it does in a nutshell, it's actually quite simple:
>
> $foo = 'bar';
> $bar = 'foobar';
> echo $$foo;    //This prints foobar
>
> What it does is, take the value of $foo (which is 'bar') and if a
> variable exists by that name, it will go forth and print the value of
> $bar; In this case foobar.
>

Alright Russel, Thank you,
Ashim.

--- End Message ---
--- Begin Message ---
Just being curious, I have a question.
How many times PHP interpreter will replace this variables? I mean how deep
it will be?

If I use variable variables like
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$a
how long it will be evaluated?

-- 
Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
Innovation distinguishes between follower and leader

--- End Message ---
--- Begin Message ---
∞

2011/3/6 shiplu <[email protected]>

> Just being curious, I have a question.
> How many times PHP interpreter will replace this variables? I mean how deep
> it will be?
>
> If I use variable variables like
>
> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$a
> how long it will be evaluated?
>
> --
> Shiplu Mokadd.im
> My talks, http://talk.cmyweb.net
> Follow me, http://twitter.com/shiplu
> Innovation distinguishes between follower and leader
>

--- End Message ---
--- Begin Message ---
On Sun, 6 Mar 2011 21:12:34 +0600, shiplu wrote:
>
> Just being curious, I have a question.
> How many times PHP interpreter will replace this variables? I mean how deep
> it will be?
>
> If I use variable variables like
> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$a
> how long it will be evaluated?

What were your results when you tried it?


--- End Message ---
--- Begin Message ---
hi ! it works if there is / are emails in the box before script run (i use
cli not web based) but after it works 1 time it doesnt work again it enters
to  infinite loop ,
at that line
while(!$emails) { $emails = imap_search($inbox,'ALL'); echo "email yok\n";
print_r($emails); }

 imap_search($inbox,'ALL'); it doesn't try to research emails in $inbox,
doesn't it stay as connected or it's just for 1 time use :S ? should i reuse
imap_open everytime when i need to use imap_search ?

$inbox = imap_open($hostname,$usernamex,$password) or die('Cannot connect to
domain:' . imap_last_error());

function onayla()
{
global $inbox;
$emails = imap_search($inbox,'ALL');
while(!$emails) { $emails = imap_search($inbox,'ALL'); echo "email yok\n";
print_r($emails); }
echo "\nyeaah"; print_r($emails);
if($emails) {
rsort($emails);
echo "Number of email:".imap_num_msg($inbox);
foreach($emails as $email_number) {

$overview = imap_fetch_overview($inbox,$email_number,0);
if(stristr($overview[0]->subject,"Test"))
{
$message = imap_fetchbody($inbox,$email_number,1);
echo "$message\n\r";
//$link=arasi('activate:','-- The',$message); //echo "\n\r".$link;
#fwrite(fopen("deneme.txt",w),file_get_contents($link));
//imap_delete($inbox,'1:*');
//imap_expunge($inbox);
}


}

}
imap_delete($inbox,'1:*');
imap_expunge($inbox);
}

--- End Message ---
--- Begin Message ---
It doesn't though, it creates a copy of the $_GLOBALS super global array,
removes entries that will have been set by the system (i.e. it leaves
user-defined variables) and then returns the ones that are left, so in that,
the user note is perfectly correct.

What has me puzzled is how unsetting LEAVES user defined variables ? Why
would that happen ?

The array in the function lists the common server-defined variables
> (HTTP_VARS, etc), which it unsets from the local copy of the super global
> array ($globals). Basically, it loops through the un-named array, and unsets
> that index from $globals.
>

Thank you,
Ashim

--- End Message ---

Reply via email to