[PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
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
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



[PHP] Watch out for automatic type casting

2012-03-29 Thread Arno Kuhl
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..text

 

In fact it ends up being:

tis.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



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
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 

> 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 " '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
>
>


Re: [PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
OK. So what would be a good way to validate a date?

El día 29 de marzo de 2012 14:04, David OBrien  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 
>>
>> 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 "> '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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
http://www.php.net/manual/en/function.checkdate.php

2012/3/29 Martín Marqués 

> OK. So what would be a good way to validate a date?
>
> El día 29 de marzo de 2012 14:04, David OBrien 
> 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 
> >>
> >> 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 " >> '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
>


Re: [PHP] Watch out for automatic type casting

2012-03-29 Thread Simon Schick
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 :
> 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..text
>
>
>
> In fact it ends up being:
>
> tis.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
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
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 

> http://www.php.net/manual/en/function.checkdate.php
>
>
> 2012/3/29 Martín Marqués 
>
>> OK. So what would be a good way to validate a date?
>>
>> El día 29 de marzo de 2012 14:04, David OBrien 
>> 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 
>> >>
>> >> 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 "> >> '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
>>
>
>


Re: [PHP] Watch out for automatic type casting

2012-03-29 Thread Simon Schick
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 :
> 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 :
>> 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..text
>>
>>
>>
>> In fact it ends up being:
>>
>> tis.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
>>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Watch out for automatic type casting

2012-03-29 Thread Stuart Dallas
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..text
> 
> 
> 
> In fact it ends up being:
> 
> tis.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



Re: [PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
El día 29 de marzo de 2012 14:14, David OBrien  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



[PHP] Re: [PHP-DB] Flow of PHP testClass

2012-03-29 Thread tamouse mailing lists
On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh  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.
>
>  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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DB] Flow of PHP testClass

2012-03-29 Thread tamouse mailing lists
On Thu, Mar 29, 2012 at 1:17 PM, tamouse mailing lists
 wrote:
> On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh  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.
>>
>> > 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:


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?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DB] Flow of PHP testClass

2012-03-29 Thread tamouse mailing lists
On Thu, Mar 29, 2012 at 1:30 PM, tamouse mailing lists
 wrote:
> On Thu, Mar 29, 2012 at 1:17 PM, tamouse mailing lists
>  wrote:
>> On Thu, Mar 29, 2012 at 9:57 AM, Rikin Parekh  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.
>>>
>>> >> 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:
>
>
>  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:


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();
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread tamouse mailing lists
2012/3/29 Martín Marqués :
> El día 29 de marzo de 2012 14:14, David OBrien  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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Watch out for automatic type casting

2012-03-29 Thread tamouse mailing lists
On Thu, Mar 29, 2012 at 12:19 PM, Stuart Dallas  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..text
>>
>>
>>
>> In fact it ends up being:
>>
>> tis.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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] pcntl_fork behavior with php version 5.1.2

2012-03-29 Thread Ralf Gnädinger
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
 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


Re: [PHP] pcntl_fork behavior with php version 5.1.2

2012-03-29 Thread Jim Lucas

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
  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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pcntl_fork behavior with php version 5.1.2

2012-03-29 Thread Stuart Dallas
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
>  
> $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/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pcntl_fork behavior with php version 5.1.2

2012-03-29 Thread Ralf Gnädinger
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 :

> 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
>> >
>> $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/
>


Re: [PHP] pcntl_fork behavior with php version 5.1.2

2012-03-29 Thread Ralf Gnädinger
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 :

> 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
> >  >
> > $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/


[PHP] Updating Google Plus

2012-03-29 Thread Brian Dunning
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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Updating Google Plus

2012-03-29 Thread Stuart Dallas
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/

Re: [PHP] Updating Google Plus

2012-03-29 Thread Brian Dunning
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?!?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Updating Google Plus

2012-03-29 Thread Stuart Dallas
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/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Updating Google Plus

2012-03-29 Thread Brian Dunning
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?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP 5.4.1 RC1 Released

2012-03-29 Thread Stas Malyshev
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Watch out for automatic type casting

2012-03-29 Thread Arno Kuhl
-Original Message-
From: Simon Schick [mailto:simonsimc...@googlemail.com] 
Sent: 29 March 2012 07:19 PM
To: a...@dotcontent.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] Watch out for automatic type casting

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


Thanks Simon and others, thought it was typecasting, but precedence makes more 
sense.

I remember seeing that table when I first started using php, which is why I 
always use AND and OR rather than && and || because it's lower precedence than 
the assignment and the ternary operators, but I couldn't remember where I'd 
seen it. So thanks for linking to it.

Cheers
Arno


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php