php-general Digest 30 Mar 2012 06:23:29 -0000 Issue 7752

Topics (messages 317338 through 317362):

Watch out for automatic type casting
        317338 by: Arno Kuhl
        317342 by: Simon Schick
        317344 by: Simon Schick
        317345 by: Stuart Dallas
        317351 by: tamouse mailing lists

Re: DateTime wierdness
        317339 by: David OBrien
        317340 by: Martín Marqués
        317341 by: David OBrien
        317343 by: David OBrien
        317346 by: Martín Marqués
        317350 by: tamouse mailing lists

Re: [PHP-DB] Flow of PHP testClass
        317347 by: tamouse mailing lists
        317348 by: tamouse mailing lists
        317349 by: tamouse mailing lists

pcntl_fork behavior with php version 5.1.2
        317352 by: Ralf Gnädinger
        317353 by: Jim Lucas
        317354 by: Stuart Dallas
        317355 by: Ralf Gnädinger
        317356 by: Ralf Gnädinger

Updating Google Plus
        317357 by: Brian Dunning
        317358 by: Stuart Dallas
        317359 by: Brian Dunning
        317360 by: Stuart Dallas
        317361 by: Brian Dunning

PHP 5.4.1 RC1 Released
        317362 by: Stas Malyshev

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 ---
I found automatic typecasting can be a bit of a gotcha.

 

$sText = "this.is.a.test.text";

if ( $pos = strpos($sText, "test") !== FALSE) {

                echo  substr($sText, 0, $pos)."<".substr($sText, $pos,
strlen("test")).">".substr($sText, $pos+strlen("test"));

}

 

The code seems logical enough, and the expected result would be:

this.is.a.<test>.text

 

In fact it ends up being:

t<his.>is.a.test.text

 

The reason is $pos is typecast as TRUE, not int 10, presumably because it's
in the same scope as the boolean test.

Then when $pos is later used as an int it's converted from TRUE to 1.

 

You have to bracket the $pos setting to move it into its own scope to
prevent it being typecast:

if ( ($pos = strpos($sText, "test")) !== FALSE) {

 

No doubt it's mentioned somewhere in the php manual, I just never came
across it.

Just thought I'd highlight one of the gotchas of auto typecasting for any
other simpletons like me.

 

Cheers

Arno


--- End Message ---
--- Begin Message ---
Hi, Arno

I don't know if this is written somewhere in the php-manual, but I
really like this table:
http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

I do not really understand why this has some special stuff to do with
typecasting ... This is just an order like the operators + and * in
math.
If you'd ask me, this is exactly what I would expect to happen.

Bye
Simon

2012/3/29 Arno Kuhl <a...@dotcontent.net>:
> I found automatic typecasting can be a bit of a gotcha.
>
>
>
> $sText = "this.is.a.test.text";
>
> if ( $pos = strpos($sText, "test") !== FALSE) {
>
>                echo  substr($sText, 0, $pos)."<".substr($sText, $pos,
> strlen("test")).">".substr($sText, $pos+strlen("test"));
>
> }
>
>
>
> The code seems logical enough, and the expected result would be:
>
> this.is.a.<test>.text
>
>
>
> In fact it ends up being:
>
> t<his.>is.a.test.text
>
>
>
> The reason is $pos is typecast as TRUE, not int 10, presumably because it's
> in the same scope as the boolean test.
>
> Then when $pos is later used as an int it's converted from TRUE to 1.
>
>
>
> You have to bracket the $pos setting to move it into its own scope to
> prevent it being typecast:
>
> if ( ($pos = strpos($sText, "test")) !== FALSE) {
>
>
>
> No doubt it's mentioned somewhere in the php manual, I just never came
> across it.
>
> Just thought I'd highlight one of the gotchas of auto typecasting for any
> other simpletons like me.
>
>
>
> Cheers
>
> Arno
>

--- End Message ---
--- Begin Message ---
Hi, Arno

FYI: I found a page in the php-manual that's exactly for that:
http://www.php.net/manual/en/language.operators.precedence.php

p.s. some of them were also new to me .... Thanks for getting me to read it.

Bye
Simon

2012/3/29 Simon Schick <simonsimc...@googlemail.com>:
> Hi, Arno
>
> I don't know if this is written somewhere in the php-manual, but I
> really like this table:
> http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages
>
> I do not really understand why this has some special stuff to do with
> typecasting ... This is just an order like the operators + and * in
> math.
> If you'd ask me, this is exactly what I would expect to happen.
>
> Bye
> Simon
>
> 2012/3/29 Arno Kuhl <a...@dotcontent.net>:
>> I found automatic typecasting can be a bit of a gotcha.
>>
>>
>>
>> $sText = "this.is.a.test.text";
>>
>> if ( $pos = strpos($sText, "test") !== FALSE) {
>>
>>                echo  substr($sText, 0, $pos)."<".substr($sText, $pos,
>> strlen("test")).">".substr($sText, $pos+strlen("test"));
>>
>> }
>>
>>
>>
>> The code seems logical enough, and the expected result would be:
>>
>> this.is.a.<test>.text
>>
>>
>>
>> In fact it ends up being:
>>
>> t<his.>is.a.test.text
>>
>>
>>
>> The reason is $pos is typecast as TRUE, not int 10, presumably because it's
>> in the same scope as the boolean test.
>>
>> Then when $pos is later used as an int it's converted from TRUE to 1.
>>
>>
>>
>> You have to bracket the $pos setting to move it into its own scope to
>> prevent it being typecast:
>>
>> if ( ($pos = strpos($sText, "test")) !== FALSE) {
>>
>>
>>
>> No doubt it's mentioned somewhere in the php manual, I just never came
>> across it.
>>
>> Just thought I'd highlight one of the gotchas of auto typecasting for any
>> other simpletons like me.
>>
>>
>>
>> Cheers
>>
>> Arno
>>

--- End Message ---
--- Begin Message ---
On 29 Mar 2012, at 17:57, Arno Kuhl wrote:

> I found automatic typecasting can be a bit of a gotcha.
> 
> 
> 
> $sText = "this.is.a.test.text";
> 
> if ( $pos = strpos($sText, "test") !== FALSE) {
> 
>                echo  substr($sText, 0, $pos)."<".substr($sText, $pos,
> strlen("test")).">".substr($sText, $pos+strlen("test"));
> 
> }
> 
> 
> 
> The code seems logical enough, and the expected result would be:
> 
> this.is.a.<test>.text
> 
> 
> 
> In fact it ends up being:
> 
> t<his.>is.a.test.text
> 
> 
> 
> The reason is $pos is typecast as TRUE, not int 10, presumably because it's
> in the same scope as the boolean test.
> 
> Then when $pos is later used as an int it's converted from TRUE to 1.
> 
> 
> 
> You have to bracket the $pos setting to move it into its own scope to
> prevent it being typecast:
> 
> if ( ($pos = strpos($sText, "test")) !== FALSE) {
> 
> 
> 
> No doubt it's mentioned somewhere in the php manual, I just never came
> across it.
> 
> Just thought I'd highlight one of the gotchas of auto typecasting for any
> other simpletons like me.

This is not due to typecasting, it's due to operator precedence.

In PHP (and many other languages) the !== comparison operator will get done 
first, so the result of that comparison will be assigned to $pos. By 
introducing the brackets you're explicitly specifying the order.

Details here: http://php.net/operators.precedence

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On Thu, Mar 29, 2012 at 12:19 PM, Stuart Dallas <stu...@3ft9.com> wrote:
> On 29 Mar 2012, at 17:57, Arno Kuhl wrote:
>
>> I found automatic typecasting can be a bit of a gotcha.
>>
>>
>>
>> $sText = "this.is.a.test.text";
>>
>> if ( $pos = strpos($sText, "test") !== FALSE) {
>>
>>                echo  substr($sText, 0, $pos)."<".substr($sText, $pos,
>> strlen("test")).">".substr($sText, $pos+strlen("test"));
>>
>> }
>>
>>
>>
>> The code seems logical enough, and the expected result would be:
>>
>> this.is.a.<test>.text
>>
>>
>>
>> In fact it ends up being:
>>
>> t<his.>is.a.test.text
>>
>>
>>
>> The reason is $pos is typecast as TRUE, not int 10, presumably because it's
>> in the same scope as the boolean test.
>>
>> Then when $pos is later used as an int it's converted from TRUE to 1.
>>
>>
>>
>> You have to bracket the $pos setting to move it into its own scope to
>> prevent it being typecast:
>>
>> if ( ($pos = strpos($sText, "test")) !== FALSE) {
>>
>>
>>
>> No doubt it's mentioned somewhere in the php manual, I just never came
>> across it.
>>
>> Just thought I'd highlight one of the gotchas of auto typecasting for any
>> other simpletons like me.
>
> This is not due to typecasting, it's due to operator precedence.
>
> In PHP (and many other languages) the !== comparison operator will get done 
> first, so the result of that comparison will be assigned to $pos. By 
> introducing the brackets you're explicitly specifying the order.
>
> Details here: http://php.net/operators.precedence
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Interestingly enough (again due to precedence + LR processing) if you
reverse the order of the test:

if (false !== $pos = strpos($sText, "test"))

it works! But I'm not sure it's a good idea to rely on that, as the
extra bracketing is probably more obvious to the reader.

--- End Message ---
--- Begin Message ---
echo date("m-d-y",mktime(0, 0, 0, 14, 14, 2012));

this outputs "02-14-13" also so my guess is that it is being interpreted
the same as  "12/14/2012 +2 months"

echo date("m-d-y",mktime(0, 0, 0, 1, 45, 2012)); outputs
"02-14-12"

which is 1/1/12 +45 days



2012/3/29 Martín Marqués <martin.marq...@gmail.com>

> Can someone explain to me this weierdness I see when using the
> DateTime module of PHP.
>
> Here I send 14/14/2012 which is not a valid date, and I would expect
> to recieve false, but instead, it looks like it wrapping to the next
> year, as if 14 monthas are 1 year and 2 months. That isn't what's
> supposed to happen, or is it?
>
> $ echo "<?php var_dump(DateTime::createFromFormat('j/n/Y',
> '14/14/2012')); ?> "|php
> object(DateTime)#1 (3) {
>  ["date"]=>
>  string(19) "2013-02-14 13:20:22"
>  ["timezone_type"]=>
>  int(3)
>  ["timezone"]=>
>  string(20) "America/Buenos_Aires"
> }
>
>
> --
> Martín Marqués
> select 'martin.marques' || '@' || 'gmail.com'
> DBA, Programador, Administrador
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
OK. So what would be a good way to validate a date?

El día 29 de marzo de 2012 14:04, David OBrien <dgobr...@gmail.com> escribió:
>
> echo date("m-d-y",mktime(0, 0, 0, 14, 14, 2012));
>
> this outputs "02-14-13" also so my guess is that it is being interpreted the
> same as  "12/14/2012 +2 months"
>
> echo date("m-d-y",mktime(0, 0, 0, 1, 45, 2012)); outputs
> "02-14-12"
>
> which is 1/1/12 +45 days
>
>
>
> 2012/3/29 Martín Marqués <martin.marq...@gmail.com>
>>
>> Can someone explain to me this weierdness I see when using the
>> DateTime module of PHP.
>>
>> Here I send 14/14/2012 which is not a valid date, and I would expect
>> to recieve false, but instead, it looks like it wrapping to the next
>> year, as if 14 monthas are 1 year and 2 months. That isn't what's
>> supposed to happen, or is it?
>>
>> $ echo "<?php var_dump(DateTime::createFromFormat('j/n/Y',
>> '14/14/2012')); ?> "|php
>> object(DateTime)#1 (3) {
>>  ["date"]=>
>>  string(19) "2013-02-14 13:20:22"
>>  ["timezone_type"]=>
>>  int(3)
>>  ["timezone"]=>
>>  string(20) "America/Buenos_Aires"
>> }
>>
>>
>> --
>> Martín Marqués
>> select 'martin.marques' || '@' || 'gmail.com'
>> DBA, Programador, Administrador
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>



-- 
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

--- End Message ---
--- Begin Message ---
http://www.php.net/manual/en/function.checkdate.php

2012/3/29 Martín Marqués <martin.marq...@gmail.com>

> OK. So what would be a good way to validate a date?
>
> El día 29 de marzo de 2012 14:04, David OBrien <dgobr...@gmail.com>
> escribió:
> >
> > echo date("m-d-y",mktime(0, 0, 0, 14, 14, 2012));
> >
> > this outputs "02-14-13" also so my guess is that it is being interpreted
> the
> > same as  "12/14/2012 +2 months"
> >
> > echo date("m-d-y",mktime(0, 0, 0, 1, 45, 2012)); outputs
> > "02-14-12"
> >
> > which is 1/1/12 +45 days
> >
> >
> >
> > 2012/3/29 Martín Marqués <martin.marq...@gmail.com>
> >>
> >> Can someone explain to me this weierdness I see when using the
> >> DateTime module of PHP.
> >>
> >> Here I send 14/14/2012 which is not a valid date, and I would expect
> >> to recieve false, but instead, it looks like it wrapping to the next
> >> year, as if 14 monthas are 1 year and 2 months. That isn't what's
> >> supposed to happen, or is it?
> >>
> >> $ echo "<?php var_dump(DateTime::createFromFormat('j/n/Y',
> >> '14/14/2012')); ?> "|php
> >> object(DateTime)#1 (3) {
> >>  ["date"]=>
> >>  string(19) "2013-02-14 13:20:22"
> >>  ["timezone_type"]=>
> >>  int(3)
> >>  ["timezone"]=>
> >>  string(20) "America/Buenos_Aires"
> >> }
> >>
> >>
> >> --
> >> Martín Marqués
> >> select 'martin.marques' || '@' || 'gmail.com'
> >> DBA, Programador, Administrador
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
>
>
>
> --
> Martín Marqués
> select 'martin.marques' || '@' || 'gmail.com'
> DBA, Programador, Administrador
>

--- End Message ---
--- Begin Message ---
actually this would work well ... compare what they send with the output of
the formatdate

function checkDateTime($data) {
    if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
        return true;
    } else {
        return false;
    }
}

2012/3/29 David OBrien <dgobr...@gmail.com>

> http://www.php.net/manual/en/function.checkdate.php
>
>
> 2012/3/29 Martín Marqués <martin.marq...@gmail.com>
>
>> OK. So what would be a good way to validate a date?
>>
>> El día 29 de marzo de 2012 14:04, David OBrien <dgobr...@gmail.com>
>> escribió:
>> >
>> > echo date("m-d-y",mktime(0, 0, 0, 14, 14, 2012));
>> >
>> > this outputs "02-14-13" also so my guess is that it is being
>> interpreted the
>> > same as  "12/14/2012 +2 months"
>> >
>> > echo date("m-d-y",mktime(0, 0, 0, 1, 45, 2012)); outputs
>> > "02-14-12"
>> >
>> > which is 1/1/12 +45 days
>> >
>> >
>> >
>> > 2012/3/29 Martín Marqués <martin.marq...@gmail.com>
>> >>
>> >> Can someone explain to me this weierdness I see when using the
>> >> DateTime module of PHP.
>> >>
>> >> Here I send 14/14/2012 which is not a valid date, and I would expect
>> >> to recieve false, but instead, it looks like it wrapping to the next
>> >> year, as if 14 monthas are 1 year and 2 months. That isn't what's
>> >> supposed to happen, or is it?
>> >>
>> >> $ echo "<?php var_dump(DateTime::createFromFormat('j/n/Y',
>> >> '14/14/2012')); ?> "|php
>> >> object(DateTime)#1 (3) {
>> >>  ["date"]=>
>> >>  string(19) "2013-02-14 13:20:22"
>> >>  ["timezone_type"]=>
>> >>  int(3)
>> >>  ["timezone"]=>
>> >>  string(20) "America/Buenos_Aires"
>> >> }
>> >>
>> >>
>> >> --
>> >> Martín Marqués
>> >> select 'martin.marques' || '@' || 'gmail.com'
>> >> DBA, Programador, Administrador
>> >>
>> >> --
>> >> PHP General Mailing List (http://www.php.net/)
>> >> To unsubscribe, visit: http://www.php.net/unsub.php
>> >>
>> >
>>
>>
>>
>> --
>> Martín Marqués
>> select 'martin.marques' || '@' || 'gmail.com'
>> DBA, Programador, Administrador
>>
>
>

--- End Message ---
--- Begin Message ---
El día 29 de marzo de 2012 14:14, David OBrien <dgobr...@gmail.com> escribió:
> actually this would work well ... compare what they send with the output of
> the formatdate
>
> function checkDateTime($data) {
>     if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
>         return true;
>     } else {
>         return false;
>
>     }
> }

Well, I did somethin similar...

    $arDate = explode("/", $nacimiento);
    if(!checkdate($arDate[1], $arDate[0], $arDate[2]))
      $nacimiento = '';

Just need to set the variable $nacimiento to the empty string if it's
not a valid date.

Thanks anyway,


-- 
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

--- End Message ---
--- Begin Message ---
2012/3/29 Martín Marqués <martin.marq...@gmail.com>:
> El día 29 de marzo de 2012 14:14, David OBrien <dgobr...@gmail.com> escribió:
>> actually this would work well ... compare what they send with the output of
>> the formatdate
>>
>> function checkDateTime($data) {
>>     if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
>>         return true;
>>     } else {
>>         return false;
>>
>>     }
>> }
>
> Well, I did somethin similar...
>
>    $arDate = explode("/", $nacimiento);
>    if(!checkdate($arDate[1], $arDate[0], $arDate[2]))
>      $nacimiento = '';
>
> Just need to set the variable $nacimiento to the empty string if it's
> not a valid date.
>
> Thanks anyway,
>
>
> --
> Martín Marqués
> select 'martin.marques' || '@' || 'gmail.com'
> DBA, Programador, Administrador
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

I don't know how it came to be, but a lot of people rely on this
behaviour. It does make sense if you squint at it a bit -- trust that
the programmer meant what they said and deliver something useful,
leave error checking up to the programmer. I'm a bit ambivalent about
it, personally, but the way it's implemented does seem more flexible.

--- End Message ---
--- Begin Message ---
On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh <riki...@gmail.com> wrote:
> Hi Guys,
>
> Given below is a PHP script. Can someone help me with the output of the
> code. According to my understanding the output should be 3, 50, 20, 10. Can
> someone elaborate on the same and provide me an explanation on the flow?
>
> Thanks a lot in advance.
>
> <?php
> class TestClass {
> var $a =20;
> var $b =10;
> function TestClass($a= null, $b=null) {
>  if (!is_null($a))
>  {
>   $this-­‐>a= $a;
>  }
> if(!is_null($b))
>  {
>  $this-­‐>b=$b;
>  }
> }
>
> function printAB() {
> echo $this-­‐>a.” “.$this-­‐>b.”\n”;
>  }
> }
>
> $inst1 = new TestClass(3,50);
> $inst2 = new TestClass();
> $inst1-­‐>printAB();
> $inst2-­‐>printAB();
> ?>

It'd be great if you provided the output you are getting.

--- End Message ---
--- Begin Message ---
On Thu, Mar 29, 2012 at 1:17 PM, tamouse mailing lists
<tamouse.li...@gmail.com> wrote:
> On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh <riki...@gmail.com> wrote:
>> Hi Guys,
>>
>> Given below is a PHP script. Can someone help me with the output of the
>> code. According to my understanding the output should be 3, 50, 20, 10. Can
>> someone elaborate on the same and provide me an explanation on the flow?
>>
>> Thanks a lot in advance.
>>
>> <?php
>> class TestClass {
>> var $a =20;
>> var $b =10;
>> function TestClass($a= null, $b=null) {
>>  if (!is_null($a))
>>  {
>>   $this-­‐>a= $a;
>>  }
>> if(!is_null($b))
>>  {
>>  $this-­‐>b=$b;
>>  }
>> }
>>
>> function printAB() {
>> echo $this-­‐>a.” “.$this-­‐>b.”\n”;
>>  }
>> }
>>
>> $inst1 = new TestClass(3,50);
>> $inst2 = new TestClass();
>> $inst1-­‐>printAB();
>> $inst2-­‐>printAB();
>> ?>
>
> It'd be great if you provided the output you are getting.

After cleaning up the code (I think the mail system might have stuck
in some weird characters, this is what I got:


<?php
error_reporting(-1);
ini_set('display_errors',true);
ini_set('display_startup_errors',true);

class TestClass {
  public $a=20;
  public $b=10;
  public function TestClass($a= null, $b=null) {
    if (!is_null($a))
      {
        $this->a = $a;
      }
    if(!is_null($b))
      {
        $this->b=$b;
      }
  }

  public function printAB() {
    echo $this->a." ".$this->b."\n";
  }
}

$inst1 = new TestClass(3,50);
$inst2 = new TestClass();
$inst1->printAB();
$inst2->printAB();
?>

Outputs:

3 50 20 10

as you expect. What is the question?

--- End Message ---
--- Begin Message ---
On Thu, Mar 29, 2012 at 1:30 PM, tamouse mailing lists
<tamouse.li...@gmail.com> wrote:
> On Thu, Mar 29, 2012 at 1:17 PM, tamouse mailing lists
> <tamouse.li...@gmail.com> wrote:
>> On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh <riki...@gmail.com> wrote:
>>> Hi Guys,
>>>
>>> Given below is a PHP script. Can someone help me with the output of the
>>> code. According to my understanding the output should be 3, 50, 20, 10. Can
>>> someone elaborate on the same and provide me an explanation on the flow?
>>>
>>> Thanks a lot in advance.
>>>
>>> <?php
>>> class TestClass {
>>> var $a =20;
>>> var $b =10;
>>> function TestClass($a= null, $b=null) {
>>>  if (!is_null($a))
>>>  {
>>>   $this-­‐>a= $a;
>>>  }
>>> if(!is_null($b))
>>>  {
>>>  $this-­‐>b=$b;
>>>  }
>>> }
>>>
>>> function printAB() {
>>> echo $this-­‐>a.” “.$this-­‐>b.”\n”;
>>>  }
>>> }
>>>
>>> $inst1 = new TestClass(3,50);
>>> $inst2 = new TestClass();
>>> $inst1-­‐>printAB();
>>> $inst2-­‐>printAB();
>>> ?>
>>
>> It'd be great if you provided the output you are getting.
>
> After cleaning up the code (I think the mail system might have stuck
> in some weird characters, this is what I got:
>
>
> <?php
> error_reporting(-1);
> ini_set('display_errors',true);
> ini_set('display_startup_errors',true);
>
> class TestClass {
>  public $a=20;
>  public $b=10;
>  public function TestClass($a= null, $b=null) {
>    if (!is_null($a))
>      {
>        $this->a = $a;
>      }
>    if(!is_null($b))
>      {
>        $this->b=$b;
>      }
>  }
>
>  public function printAB() {
>    echo $this->a." ".$this->b."\n";
>  }
> }
>
> $inst1 = new TestClass(3,50);
> $inst2 = new TestClass();
> $inst1->printAB();
> $inst2->printAB();
> ?>
>
> Outputs:
>
> 3 50 20 10
>
> as you expect. What is the question?

Crap, I didn't mean to send that. This is the actual code:


<?php
error_reporting(-1);
ini_set('display_errors',true);
ini_set('display_startup_errors',true);

class TestClass {
  var $a=20;
  var $b=10;
  function TestClass($a= null, $b=null) {
    if (!is_null($a))
      {
        $this->a = $a;
      }
    if(!is_null($b))
      {
        $this->b=$b;
      }
  }

  function printAB() {
    echo $this->a." ".$this->b."\n";
  }
}

$inst1 = new TestClass(3,50);
$inst2 = new TestClass();
$inst1->printAB();
$inst2->printAB();
?>

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

i got some trouble with a PHP script using pcntl_fork do run some work in
background.
Runnig my script on my development system (PHP version 5.3.3-7) it behaves
like
intended. But running it on my production test system (PHP version PHP
5.1.2), i got
some strange results. The problem is, that when i logout from my SSH
session the
console closes not properly, like somethings is kept open. Sadly, updating
this old PHP
version is not a option... :/

Does anyone have an idea whats going on?

Thanks in advance

Ralf

The script is this:

#!/usr/bin/env php
<?php

$pid = pcntl_fork();
if ($pid == -1) {
     die('Fork failed!');
} else if($pid > 0) {

    exit(0); // close parent process

} else { // child process:

    while(true) {
        sleep(10);
        // do your work -- stripped
    }
}
?>

do not work with:
PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies


works with:
PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

--- End Message ---
--- Begin Message ---
On 03/29/2012 12:49 PM, Ralf Gnädinger wrote:
Hi,

i got some trouble with a PHP script using pcntl_fork do run some work in
background.
Runnig my script on my development system (PHP version 5.3.3-7) it behaves
like
intended. But running it on my production test system (PHP version PHP
5.1.2), i got
some strange results. The problem is, that when i logout from my SSH
session the
console closes not properly, like somethings is kept open. Sadly, updating
this old PHP
version is not a option... :/

Does anyone have an idea whats going on?

Thanks in advance

Ralf

The script is this:

#!/usr/bin/env php
<?php

$pid = pcntl_fork();
if ($pid == -1) {
      die('Fork failed!');
} else if($pid>  0) {

     exit(0); // close parent process

} else { // child process:

     while(true) {
         sleep(10);
         // do your work -- stripped
     }
}
?>

do not work with:
PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies


works with:
PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
     with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH


This sounds more like an OS issue then a PHP issue.

What are the two OSs involved?

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--- End Message ---
--- Begin Message ---
On 29 Mar 2012, at 20:49, Ralf Gnädinger wrote:

> i got some trouble with a PHP script using pcntl_fork do run some work in
> background.
> Runnig my script on my development system (PHP version 5.3.3-7) it behaves
> like
> intended. But running it on my production test system (PHP version PHP
> 5.1.2), i got
> some strange results. The problem is, that when i logout from my SSH
> session the
> console closes not properly, like somethings is kept open. Sadly, updating
> this old PHP
> version is not a option... :/
> 
> Does anyone have an idea whats going on?
> 
> Thanks in advance
> 
> Ralf
> 
> The script is this:
> 
> #!/usr/bin/env php
> <?php
> 
> $pid = pcntl_fork();
> if ($pid == -1) {
>     die('Fork failed!');
> } else if($pid > 0) {
> 
>    exit(0); // close parent process
> 
> } else { // child process:
> 
>    while(true) {
>        sleep(10);
>        // do your work -- stripped
>    }
> }
> ?>
> 
> do not work with:
> PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
> Copyright (c) 1997-2006 The PHP Group
> Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
> 
> 
> works with:
> PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40)
> Copyright (c) 1997-2009 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
>    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

You need to detach the child from the terminal using posix_setsid(). I don't 
know why it's "working" on your development machine, but it's probably simply 
that you're not seeing this issue due to how you access that development 
machine.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
development os is Debian GNU/Linux 6.0
test os is SUSE LINUX 10.1 (i586)

Am 29. März 2012 23:02 schrieb Jim Lucas <li...@cmsws.com>:

> On 03/29/2012 12:49 PM, Ralf Gnädinger wrote:
>
>> Hi,
>>
>> i got some trouble with a PHP script using pcntl_fork do run some work in
>> background.
>> Runnig my script on my development system (PHP version 5.3.3-7) it behaves
>> like
>> intended. But running it on my production test system (PHP version PHP
>> 5.1.2), i got
>> some strange results. The problem is, that when i logout from my SSH
>> session the
>> console closes not properly, like somethings is kept open. Sadly, updating
>> this old PHP
>> version is not a option... :/
>>
>> Does anyone have an idea whats going on?
>>
>> Thanks in advance
>>
>> Ralf
>>
>> The script is this:
>>
>> #!/usr/bin/env php
>> <?php
>>
>> $pid = pcntl_fork();
>> if ($pid == -1) {
>>      die('Fork failed!');
>> } else if($pid>  0) {
>>
>>     exit(0); // close parent process
>>
>> } else { // child process:
>>
>>     while(true) {
>>         sleep(10);
>>         // do your work -- stripped
>>     }
>> }
>> ?>
>>
>> do not work with:
>> PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
>> Copyright (c) 1997-2006 The PHP Group
>> Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
>>
>>
>> works with:
>> PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011
>> 08:24:40)
>> Copyright (c) 1997-2009 The PHP Group
>> Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
>>     with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
>>
>>
> This sounds more like an OS issue then a PHP issue.
>
> What are the two OSs involved?
>
> --
> Jim Lucas
>
> http://www.cmsws.com/
> http://www.cmsws.com/examples/
> http://www.bendsource.com/
>

--- End Message ---
--- Begin Message ---
I will try posix_setsid(). Both machines were accessed via a ssh client
(e.g. putty or ssh from a other linux box).

Thanks for your advice.

Am 29. März 2012 23:08 schrieb Stuart Dallas <stu...@3ft9.com>:

> On 29 Mar 2012, at 20:49, Ralf Gnädinger wrote:
>
> > i got some trouble with a PHP script using pcntl_fork do run some work in
> > background.
> > Runnig my script on my development system (PHP version 5.3.3-7) it
> behaves
> > like
> > intended. But running it on my production test system (PHP version PHP
> > 5.1.2), i got
> > some strange results. The problem is, that when i logout from my SSH
> > session the
> > console closes not properly, like somethings is kept open. Sadly,
> updating
> > this old PHP
> > version is not a option... :/
> >
> > Does anyone have an idea whats going on?
> >
> > Thanks in advance
> >
> > Ralf
> >
> > The script is this:
> >
> > #!/usr/bin/env php
> > <?php
> >
> > $pid = pcntl_fork();
> > if ($pid == -1) {
> >     die('Fork failed!');
> > } else if($pid > 0) {
> >
> >    exit(0); // close parent process
> >
> > } else { // child process:
> >
> >    while(true) {
> >        sleep(10);
> >        // do your work -- stripped
> >    }
> > }
> > ?>
> >
> > do not work with:
> > PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
> > Copyright (c) 1997-2006 The PHP Group
> > Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
> >
> >
> > works with:
> > PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011
> 08:24:40)
> > Copyright (c) 1997-2009 The PHP Group
> > Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
> >    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
>
> You need to detach the child from the terminal using posix_setsid(). I
> don't know why it's "working" on your development machine, but it's
> probably simply that you're not seeing this issue due to how you access
> that development machine.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/

--- End Message ---
--- Begin Message ---
Anyone know a way to update Google Plus via the 33669 SMS number?

Yes, I have seen the popular how-to instructions to get the secret email 
address by using Google Voice and forcing the error message, but I'd prefer a 
legit non-hack way to do it. I'd even be happy to pay for an SMS gateway rather 
than depend on the email address, which they might decide to terminate.

--- End Message ---
--- Begin Message ---
On 29 Mar 2012, at 22:44, Brian Dunning wrote:

> Anyone know a way to update Google Plus via the 33669 SMS number?
> 
> Yes, I have seen the popular how-to instructions to get the secret email 
> address by using Google Voice and forcing the error message, but I'd prefer a 
> legit non-hack way to do it. I'd even be happy to pay for an SMS gateway 
> rather than depend on the email address, which they might decide to terminate.

Err, what has this got to do with PHP?!?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
Sorry, I did not mention the implied "using PHP". Since everything I do & eat & 
breathe is PHP, it didn't even occur to me to state the obvious.  :-)  :-)


On Mar 29, 2012, at 2:46 PM, Stuart Dallas wrote:

> Err, what has this got to do with PHP?!?

--- End Message ---
--- Begin Message ---
On 29 Mar 2012, at 22:44, Brian Dunning wrote:

> Anyone know a way to update Google Plus via the 33669 SMS number?
> 
> Yes, I have seen the popular how-to instructions to get the secret email 
> address by using Google Voice and forcing the error message, but I'd prefer a 
> legit non-hack way to do it. I'd even be happy to pay for an SMS gateway 
> rather than depend on the email address, which they might decide to terminate.

"With PHP" is not a magic phrase that will make anything relevant for 
discussion on this list, but it's 2:10am and I'm feeling generous.

So, to send an SMS message with PHP...

* Use PHP to access the API for a commercial SMS gateway. There's loads of 
these, Google can find them for you. Each will likely have sample PHP code (the 
one I use, Clickatell does).

* Install something like Kannel and use PHP to access its API. I dabbled with 
this a bit, but in terms of the cost of my time it was far cheaper to use a 
commercial gateway.

* Use PHP to talk directly to a mobile phone through a serial interface. Ditto 
as far as the reason why I didn't go down this route. I tried it back in the 
late 90s and it was fun, but commercially speaking it was a waste of time.

There's very little PHP involved here, and frankly Google could have given you 
these answers with very little effort on your part. Yeah, the generosity wore 
off :)*

-Stuart

* Smileys aren't magic either. Well, actually some are. Like the SMS you can 
send to an iPhone and it comes out looking like a whale - that's pretty magical 
and totally awesome. I think I've been staring at ColdFusion code for too long; 
I've gone all peculiar!

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
That's EXACTLY what I was looking for. Thanks! Don't know why my Google-Fu 
failed me...  :-)

On Mar 29, 2012, at 5:26 PM, Don Wieland wrote:

> First Google+ (Google Plus) status update bot in PHP
> http://360percents.com/posts/first-google-google-plus-status-update-bot-in-php/
> Is that what you are looking for or something different?


--- End Message ---
--- Begin Message ---
Hi!

We would like to announce the first RC of the 5.4.1 version. This will
be mainly a bugfix version, including all bugfixes that did not make the
cut for 5.4.0 and new issues since then. Please test it and notify us of
any problems you may encounter.
The full list of the fixes is as always in the NEWS file.

You can download the packages from:

    http://downloads.php.net/stas

The Windows team provides windows binaries for the release.
As always you find them at:

    http://windows.php.net/qa/

This is also the first release we are making from our brand new Git
setup, please tell us if you notice any glitches. You can
read more about the Git migration here:
http://www.php.net/archive/2012.php#id2012-03-20-1

We plan the next RC for 5.4.1 in two weeks, on April 5th.

Regards,
  Stas & David

--- End Message ---

Reply via email to