php-general Digest 17 Sep 2012 21:12:33 -0000 Issue 7967

Topics (messages 319108 through 319113):

Re: Expected behaviour or bug?
        319108 by: Frank Arensmeier
        319109 by: Simon J Welsh
        319110 by: Camilo Sperberg
        319111 by: Matijn Woudt

Re: bucle while for to msqyl
        319112 by: El Ale...

tricky code problem
        319113 by: Jim Giner

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
17 sep 2012 kl. 10.50 skrev Camilo Sperberg:

> Hello list, I have a little question with PHP's internal working. I've 
> managed to reduce the test to the following lines:
> 
> $globalVariable = 'i am a global variable';
> function testFunction() {
>       global $globalVariable;
>       unset($globalVariable);
> }
> 
> testFunction();
> 
> if(isset($globalVariable)) {
>       var_dump('global variable IS set');
> } else {
>       var_dump('global variable is NOT set');
> }
> 
> 
> 
> When executing the above test, you will get printed that the global variable 
> is set, despite unsetting it in the function. Is it really the intention to 
> unset a global variable inside a function locally or have I just happen to 
> found a little bug?
> 
> unreal4u-MBP:~ unreal4u$ php --version
> PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>    with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
> 
> If it is expected behavior, is there any documentation on why this is done 
> this way?
> 
> Greetings and thanks.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
Sometimes, it helps reading the manual...

http://lmgtfy.com/?q=php+unset+global

"If a globalized variable is unset() inside of a function, only the local 
variable is destroyed. The variable in the calling environment will retain the 
same value as before unset() was called."
[...]
"To unset() a global variable inside of a function, then use the$GLOBALS array 
to do so:"

Took about 1 minute to find out.

/frank

--- End Message ---
--- Begin Message ---
On 17/09/2012, at 8:50 PM, Camilo Sperberg <unrea...@gmail.com> wrote:

> Hello list, I have a little question with PHP's internal working. I've 
> managed to reduce the test to the following lines:
> 
> $globalVariable = 'i am a global variable';
> function testFunction() {
>       global $globalVariable;
>       unset($globalVariable);
> }
> 
> testFunction();
> 
> if(isset($globalVariable)) {
>       var_dump('global variable IS set');
> } else {
>       var_dump('global variable is NOT set');
> }
> 
> 
> 
> When executing the above test, you will get printed that the global variable 
> is set, despite unsetting it in the function. Is it really the intention to 
> unset a global variable inside a function locally or have I just happen to 
> found a little bug?
> 
> unreal4u-MBP:~ unreal4u$ php --version
> PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>    with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
> 
> If it is expected behavior, is there any documentation on why this is done 
> this way?
> 
> Greetings and thanks.


That's expected, as per http://nz.php.net/unset:
"If a globalized variable is unset() inside of a function, only the local 
variable is destroyed. The variable in the calling environment will retain the 
same value as before unset() was called."
---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---
--- Begin Message ---
On 17 sep. 2012, at 10:55, Frank Arensmeier <farensme...@gmail.com> wrote:

> 17 sep 2012 kl. 10.50 skrev Camilo Sperberg:
> 
>> Hello list, I have a little question with PHP's internal working. I've 
>> managed to reduce the test to the following lines:
>> 
>> $globalVariable = 'i am a global variable';
>> function testFunction() {
>>      global $globalVariable;
>>      unset($globalVariable);
>> }
>> 
>> testFunction();
>> 
>> if(isset($globalVariable)) {
>>      var_dump('global variable IS set');
>> } else {
>>      var_dump('global variable is NOT set');
>> }
>> 
>> 
>> 
>> When executing the above test, you will get printed that the global variable 
>> is set, despite unsetting it in the function. Is it really the intention to 
>> unset a global variable inside a function locally or have I just happen to 
>> found a little bug?
>> 
>> unreal4u-MBP:~ unreal4u$ php --version
>> PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
>> Copyright (c) 1997-2012 The PHP Group
>> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>>   with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
>> 
>> If it is expected behavior, is there any documentation on why this is done 
>> this way?
>> 
>> Greetings and thanks.
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> Sometimes, it helps reading the manual...
> 
> http://lmgtfy.com/?q=php+unset+global
> 
> "If a globalized variable is unset() inside of a function, only the local 
> variable is destroyed. The variable in the calling environment will retain 
> the same value as before unset() was called."
> [...]
> "To unset() a global variable inside of a function, then use the$GLOBALS 
> array to do so:"
> 
> Took about 1 minute to find out.
> 
> /frank

Doh! Only thing I can say is that I tried searching but without any relevant 
terms… Thanks and also thanks to Simon!

Greetings.

--- End Message ---
--- Begin Message ---
On Mon, Sep 17, 2012 at 8:57 PM, Camilo Sperberg <unrea...@gmail.com> wrote:
>
> On 17 sep. 2012, at 10:55, Frank Arensmeier <farensme...@gmail.com> wrote:
>
>> 17 sep 2012 kl. 10.50 skrev Camilo Sperberg:
>>
>>> Hello list, I have a little question with PHP's internal working. I've 
>>> managed to reduce the test to the following lines:
>>>
>>> $globalVariable = 'i am a global variable';
>>> function testFunction() {
>>>      global $globalVariable;
>>>      unset($globalVariable);
>>> }
>>>
>>> testFunction();
>>>
>>> if(isset($globalVariable)) {
>>>      var_dump('global variable IS set');
>>> } else {
>>>      var_dump('global variable is NOT set');
>>> }
>>>
>>>
>>>
>>> When executing the above test, you will get printed that the global 
>>> variable is set, despite unsetting it in the function. Is it really the 
>>> intention to unset a global variable inside a function locally or have I 
>>> just happen to found a little bug?
>>>
>>> unreal4u-MBP:~ unreal4u$ php --version
>>> PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20)
>>> Copyright (c) 1997-2012 The PHP Group
>>> Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
>>>   with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
>>>
>>> If it is expected behavior, is there any documentation on why this is done 
>>> this way?
>>>
>>> Greetings and thanks.
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>> Sometimes, it helps reading the manual...
>>
>> http://lmgtfy.com/?q=php+unset+global
>>
>> "If a globalized variable is unset() inside of a function, only the local 
>> variable is destroyed. The variable in the calling environment will retain 
>> the same value as before unset() was called."
>> [...]
>> "To unset() a global variable inside of a function, then use the$GLOBALS 
>> array to do so:"
>>
>> Took about 1 minute to find out.
>>
>> /frank
>
> Doh! Only thing I can say is that I tried searching but without any relevant 
> terms… Thanks and also thanks to Simon!
>
> Greetings.

Just a general note, the PHP manual is pretty good.

- Matijn

--- End Message ---
--- Begin Message ---
Good people i finish thanks everyone!! this script finished:

<?

include("tempconex.php");

$stop = "SELECT estado FROM mensajes WHERE estado is NOT NULL";

do {

### comienzo script de conexion ###

$queEmp = "SELECT numero, mensaje FROM mensajes WHERE estado is NULL";
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
if ($resEmp == true) {
     while ($rowEmp = mysql_fetch_assoc($resEmp)) {
     $numero = $rowEmp['numero'];
     $mensaje  = $rowEmp['mensaje'];

### comienza el break  ###

     }
     sleep(13);
     $comando = exec('datos.log | grep "Error 500"');

     if($comando == TRUE){
     echo " error encontrado NO SE ENVIA! SE BORRA Y PAUSA 30 SEG | ";
     #mysql_query("UPDATE mensajes SET estado = 'no enviado', date = NOW()
WHERE numero = $numero", ($conexion));
     exec('cat /dev/null > datos.log');
     sleep(30);
     echo " se reanuda | ";

### termina el break ###

     }
     else
     {

### comienza el envio de el mensaje ya que no se encontro ningun error en
los logs ###

     echo " Se prepara | ";
     exec("comando de envio");
     echo " ya se envio (no se encontro ningun error) | ";
     #mysql_query("UPDATE mensajes SET estado = 'enviado', date = NOW()
WHERE numero = $numero", ($conexion));


### finaliza el envio ###

    }
   }

### fin script de conexion ###

} while ($stop == true);
        continue;
    break;
?>

its run good!, but i have one last problem, i cant if while is true
: SELECT estado FROM mensajes WHERE estado is NOT NULL play if false not
run this, im need if estado from mensajes is true loop the script but if
not break this.

I tried:

$stop = "SELECT estado FROM mensajes WHERE estado is NOT NULL";

y el while:

} while ($stop == true);
        continue;
    break;

but not run.

Thanks everyone!!

2012/9/16 El Ale... <alexissauc...@gmail.com>

> hi! im new in this forum, i not speak very good english, apologise im
> spanish.
> I have a problem, need one infinit bucle to mysql only "true" if "false"
> break this, for example:
>
> prueba.php:
>
> <?
> include("conexion.php");
>
> do {
>
>
> echo "$numero";
> sleep(1);
>
>
> if ($numero == 1)
> reset;
>         continue;
>     break;
> } while (true);
>
> ?>
>
> ############################################################3
>
> connect to mysql
>
> conexion.php:
>
> <?
>
> $conexion = mysql_connect("localhost", "alexis", "123456");
>             mysql_select_db("probando", $conexion);
> $queEmp = "SELECT n FROM numero WHERE n LIKE 1";
> $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
> $totEmp = mysql_num_rows($resEmp);
> if ($totEmp> 0) {
>      while ($rowEmp = mysql_fetch_assoc($resEmp)) {
>      $numero = $rowEmp['n'];
>
> }
> echo "$numero";
> }
> mysql_close($conexion);
> ?>
>
> What I do is to run the loop as long as the value "$ number" is equal to
> "1" in mysql I have a single field called "n" with the value "1" and runs,
> now the problem is the next, I run the loop with the value "1" in mysql and
> it runs fine but when I go to mysql and change the value to "2" (which
> would be an incorrect and should leave) the loop ignores him and continues
> running, I was reading a lot about the loops but I can not make it work in
> this way could you please give me a hand with this? or if I'm wrong What
> else I can do an infinite command if it fulfills a function and if they do
> not?.
>
> Best regards
>

--- End Message ---
--- Begin Message ---
This is a tricky one but let's see if I can explain it.

1 - using a menu screen I have a link that calls a js function that opens a popup with a form in it;

2 - the form receives some user input (a login) and then the user clicks a submit button;

3 - the button has an onclick that calls a js func that does an xmlhttprequest to a php script using a GET with some parms;

4 - the php script called above returns a true/false value back to the js function;

5 - the js function returns the true/false value back to the html <input> tag that triggered it;

6 - the form in the html containing the input tag gets submitted if the return was true, calling a different php script with a POST and definitely no parms in the action value of the <form> tag.

What shows up on my address bar (ie) is a composite of the script name called in item 6 along with the parms (ie, GET values) from the js xmlhttprequest string in item 3 appended to it. Now all of my scripts have a header that eliminates caching, so that's not it afaik. I've actually closed my session and come back an hour later and this still occurs.

Can anyone see how this can possibly be happening?

--- End Message ---

Reply via email to