Re: [PHP] Could this be a bug?

2010-09-15 Thread Thijs Lensselink

 On 09/14/2010 11:31 PM, Camilo Sperberg wrote:

On Tue, Sep 14, 2010 at 02:46, Thijs Lensselinkd...@lenss.nl  wrote:


  On 09/14/2010 08:33 AM, Thijs Lensselink wrote:


  On 09/14/2010 12:16 AM, Camilo Sperberg wrote:


I have some really strange behaviour going on here, and I think it could
be
a (minor) PHP's bug.
I am not really sure about what happens internally, but my best guess
would
be that after a memory exhaustion, when I try to execute a custom error
handler with the register_shutdown_function (which is executed even after
a
fatal error) and try to access the element that provoked the memory
exhaustion, no error should raise instead of *Uninitialized string
offset:
0.

I have prepared a little test case to reproduce the error and (I hope)
can
explain the error.

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General
Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {


This seems to be your error. You set $errctx to be a string. But later on
you use it as an array.
Remove the = '' part. And it will function as expected.


You're right... However I don't like leaving non-default value in functions
so I did something like if(empty($errctx)) $errctx = array() in the first
line of the custom error handler which threw out the error message and
everything works ok now.
I think from 5.2 and up you can use the array keyword to force an array 
as parameter..

But -and correct me if I'm wrong- isn't isset (or empty) supposed to return
a FALSE whenever that variable doesn't exist?

With your help, I could reduce the test case into:

$asdf = 'hello world';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This works ok.
This works because the string $asdf is set with a value. So $asdf[4] 
exists but ['inventing'] doesn't so it will return false

$asdf = '';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This returns E_NOTICE
This doesn't work because the string $asdf is empty. So calling $asdf[4] 
will trigger a notice since there is no 4th character

Shouldn't these 2 examples work exactly the same way? (AKA as Nº 1). If
not... why not? Both are string types, onyl difference is that one has no
characters in it while the other does, but essentialy they are both the
same.

Greetings !




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



Re: [PHP] Could this be a bug?

2010-09-14 Thread Camilo Sperberg
Well, after some more testing I'm almost sure it is some kind of strange
minor bug... so I've submitted a bug report:
http://bugs.php.net/bug.php?id=52833

Greetings !

On Tue, Sep 14, 2010 at 00:51, Camilo Sperberg unrea...@gmail.com wrote:


 On Mon, Sep 13, 2010 at 18:56, Tamara Temple tamouse.li...@gmail.comwrote:

 This isn't to answer your question, but...


 On Sep 13, 2010, at 5:16 PM, Camilo Sperberg wrote:

 function my_error_handler($errno = '0', $errstr = '[FATAL] General
 Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
   ini_set('memory_limit','16M');
   ob_start();
   echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
 ?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
 25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
 ?emError Detail:/embr /?php
   echo 'strong'.$errstr.'/strongbr /emFile:/embr
 /strong'.$errfile.'/strongbr /emLine:/embr
 /strong'.$errline.'/strongbr /emDebug:/embr /';
   if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p';
 ?/ph4-- END COPY --/h4?php
   $content = ob_get_contents();
   ob_end_clean();
   die($content);
  }
 }


 Why do you put ?php echo...? inside an echo statement in php space?



 I think you may have mis-readed the code, I can't find where I put an ?php
 echo inside an echo. I do a lot of opening/closing tags which contributes to
 messing things up estetically but it works...

 Any way, the posted code had a lot of remniscants of the production code,
 here is a simplified version which does the same as above but .. well,
 simplified :P

 ?php
 date_default_timezone_set('America/Santiago');
 ini_set('memory_limit','1M');
 ini_set('display_errors',1);
 error_reporting(-1);

 function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
   global $clean_exit;
   if(empty($clean_exit)) { // if isset or !empty, the script would have
 been exited cleanly.
 ini_set('memory_limit','16M'); // This would be just to have enough
 memory to print out the error.
 echo 'h5-- BEGIN ERROR --/h5Error Ndeg;:
 strong'.$errno.'/strongbr /Error Description:
 strong'.$errstr.'/strongbr /File: strong'.$errfile.'/strongbr
 /Line: strong'.$errline.'/strong';
 if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p'; // isset or empty gives the same error
 echo 'h5-- END ERROR --/h5';
 die(); // shutdown_function == manual die() or else it will continue to
 execute.

   }
 }
 set_error_handler('my_error_handler');
 register_shutdown_function('my_error_handler');

 for ($i = 0; $i  15000; $i++) $a[$i] = mt_rand(1,255);
 $r['print'] = (string)$a[1]; // Just to asign something to that variable.

 echo 'pEverything fine./p';
 $clean_exit = TRUE;


 Greetings :)

 --
 Mailed by:
 UnReAl4U - unreal4u
 ICQ #: 54472056
 www1: http://www.chw.net/
 www2: http://unreal4u.com/




-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Could this be a bug?

2010-09-14 Thread Thijs Lensselink

 On 09/14/2010 12:16 AM, Camilo Sperberg wrote:

I have some really strange behaviour going on here, and I think it could be
a (minor) PHP's bug.
I am not really sure about what happens internally, but my best guess would
be that after a memory exhaustion, when I try to execute a custom error
handler with the register_shutdown_function (which is executed even after a
fatal error) and try to access the element that provoked the memory
exhaustion, no error should raise instead of *Uninitialized string offset:
0.

I have prepared a little test case to reproduce the error and (I hope) can
explain the error.

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
   global $clean_exit;
   if(empty($clean_exit)) {
 ini_set('memory_limit','16M');
 ob_start();
 echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
25pxemError Ndeg;:/embr /?php
   echo 'strong'.$errno.'/strongbr /';
?emError Detail:/embr /?php
 echo 'strong'.$errstr.'/strongbr /emFile:/embr
/strong'.$errfile.'/strongbr /emLine:/embr
/strong'.$errline.'/strongbr /emDebug:/embr /';
 if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
WHAT SHOULD IT RETURN?/p';


Maybe i'm missing something here (kinda sick at home) but..
What do you expect to happen here? When i do a var_dump() on $errctx i get

string(0) 

That would explain the error you are seeing.


?/ph4-- END COPY --/h4?php
 $content = ob_get_contents();
 ob_end_clean();
 die($content);
   }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  1; $i++) $a[$i] = mt_rand(1,254);
$r['print'] = print_r($a,TRUE);
echo 'pEverything fine./p';

$clean_exit = TRUE;

*
Would this be a bug or is this expected behaviour? I have tested this on PHP
v5.2.14, I've not tested it yet on 5.3.3, but I guess it would have the same
behaviour.

Greetings!




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



Re: [PHP] Could this be a bug?

2010-09-14 Thread Thijs Lensselink

 On 09/14/2010 08:33 AM, Thijs Lensselink wrote:

 On 09/14/2010 12:16 AM, Camilo Sperberg wrote:
I have some really strange behaviour going on here, and I think it 
could be

a (minor) PHP's bug.
I am not really sure about what happens internally, but my best guess 
would

be that after a memory exhaustion, when I try to execute a custom error
handler with the register_shutdown_function (which is executed even 
after a

fatal error) and try to access the element that provoked the memory
exhaustion, no error should raise instead of *Uninitialized string 
offset:

0.

I have prepared a little test case to reproduce the error and (I 
hope) can

explain the error.

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General 
Error',

$errfile = 'N/A', $errline = 'N/A', $errctx = '') {


This seems to be your error. You set $errctx to be a string. But later 
on you use it as an array.

Remove the = '' part. And it will function as expected.


   global $clean_exit;
   if(empty($clean_exit)) {
 ini_set('memory_limit','16M');
 ob_start();
 echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
25pxemError Ndeg;:/embr /?php
   echo 'strong'.$errno.'/strongbr /';
?emError Detail:/embr /?php
 echo 'strong'.$errstr.'/strongbr /emFile:/embr
/strong'.$errfile.'/strongbr /emLine:/embr
/strong'.$errline.'/strongbr /emDebug:/embr /';
 if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE 
ERROR,

WHAT SHOULD IT RETURN?/p';


Maybe i'm missing something here (kinda sick at home) but..
What do you expect to happen here? When i do a var_dump() on $errctx i 
get


string(0) 

That would explain the error you are seeing.


?/ph4-- END COPY --/h4?php
 $content = ob_get_contents();
 ob_end_clean();
 die($content);
   }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  1; $i++) $a[$i] = mt_rand(1,254);
$r['print'] = print_r($a,TRUE);
echo 'pEverything fine./p';

$clean_exit = TRUE;

*
Would this be a bug or is this expected behaviour? I have tested this 
on PHP
v5.2.14, I've not tested it yet on 5.3.3, but I guess it would have 
the same

behaviour.

Greetings!







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



Re: [PHP] Could this be a bug?

2010-09-14 Thread Camilo Sperberg
On Tue, Sep 14, 2010 at 02:46, Thijs Lensselink d...@lenss.nl wrote:

  On 09/14/2010 08:33 AM, Thijs Lensselink wrote:

  On 09/14/2010 12:16 AM, Camilo Sperberg wrote:

 I have some really strange behaviour going on here, and I think it could
 be
 a (minor) PHP's bug.
 I am not really sure about what happens internally, but my best guess
 would
 be that after a memory exhaustion, when I try to execute a custom error
 handler with the register_shutdown_function (which is executed even after
 a
 fatal error) and try to access the element that provoked the memory
 exhaustion, no error should raise instead of *Uninitialized string
 offset:
 0.

 I have prepared a little test case to reproduce the error and (I hope)
 can
 explain the error.

 ?php
 date_default_timezone_set('America/Santiago');
 ini_set('memory_limit','1M');
 ini_set('display_errors',1);
 error_reporting(-1);

 function my_error_handler($errno = '0', $errstr = '[FATAL] General
 Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {


 This seems to be your error. You set $errctx to be a string. But later on
 you use it as an array.
 Remove the = '' part. And it will function as expected.


You're right... However I don't like leaving non-default value in functions
so I did something like if(empty($errctx)) $errctx = array() in the first
line of the custom error handler which threw out the error message and
everything works ok now.

But -and correct me if I'm wrong- isn't isset (or empty) supposed to return
a FALSE whenever that variable doesn't exist?

With your help, I could reduce the test case into:

$asdf = 'hello world';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This works ok.

$asdf = '';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This returns E_NOTICE

Shouldn't these 2 examples work exactly the same way? (AKA as Nº 1). If
not... why not? Both are string types, onyl difference is that one has no
characters in it while the other does, but essentialy they are both the
same.

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] Could this be a bug?

2010-09-13 Thread Camilo Sperberg
I have some really strange behaviour going on here, and I think it could be
a (minor) PHP's bug.
I am not really sure about what happens internally, but my best guess would
be that after a memory exhaustion, when I try to execute a custom error
handler with the register_shutdown_function (which is executed even after a
fatal error) and try to access the element that provoked the memory
exhaustion, no error should raise instead of *Uninitialized string offset:
0.

I have prepared a little test case to reproduce the error and (I hope) can
explain the error.

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
ini_set('memory_limit','16M');
ob_start();
echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
?emError Detail:/embr /?php
echo 'strong'.$errstr.'/strongbr /emFile:/embr
/strong'.$errfile.'/strongbr /emLine:/embr
/strong'.$errline.'/strongbr /emDebug:/embr /';
if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
WHAT SHOULD IT RETURN?/p';
?/ph4-- END COPY --/h4?php
$content = ob_get_contents();
ob_end_clean();
die($content);
  }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  1; $i++) $a[$i] = mt_rand(1,254);
$r['print'] = print_r($a,TRUE);
echo 'pEverything fine./p';

$clean_exit = TRUE;

*
Would this be a bug or is this expected behaviour? I have tested this on PHP
v5.2.14, I've not tested it yet on 5.3.3, but I guess it would have the same
behaviour.

Greetings!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Could this be a bug?

2010-09-13 Thread Tamara Temple

This isn't to answer your question, but...

On Sep 13, 2010, at 5:16 PM, Camilo Sperberg wrote:
function my_error_handler($errno = '0', $errstr = '[FATAL] General  
Error',

$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
 global $clean_exit;
 if(empty($clean_exit)) {
   ini_set('memory_limit','16M');
   ob_start();
   echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
25pxemError Ndeg;:/embr /?php
 echo 'strong'.$errno.'/strongbr /';
?emError Detail:/embr /?php
   echo 'strong'.$errstr.'/strongbr /emFile:/embr
/strong'.$errfile.'/strongbr /emLine:/embr
/strong'.$errline.'/strongbr /emDebug:/embr /';
   if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE  
ERROR,

WHAT SHOULD IT RETURN?/p';
?/ph4-- END COPY --/h4?php
   $content = ob_get_contents();
   ob_end_clean();
   die($content);
 }
}


Why do you put ?php echo...? inside an echo statement in php space?


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



Re: [PHP] Could this be a bug?

2010-09-13 Thread Camilo Sperberg
On Mon, Sep 13, 2010 at 18:56, Tamara Temple tamouse.li...@gmail.comwrote:

 This isn't to answer your question, but...


 On Sep 13, 2010, at 5:16 PM, Camilo Sperberg wrote:

 function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
   ini_set('memory_limit','16M');
   ob_start();
   echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
 ?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
 25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
 ?emError Detail:/embr /?php
   echo 'strong'.$errstr.'/strongbr /emFile:/embr
 /strong'.$errfile.'/strongbr /emLine:/embr
 /strong'.$errline.'/strongbr /emDebug:/embr /';
   if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p';
 ?/ph4-- END COPY --/h4?php
   $content = ob_get_contents();
   ob_end_clean();
   die($content);
  }
 }


 Why do you put ?php echo...? inside an echo statement in php space?



I think you may have mis-readed the code, I can't find where I put an ?php
echo inside an echo. I do a lot of opening/closing tags which contributes to
messing things up estetically but it works...

Any way, the posted code had a lot of remniscants of the production code,
here is a simplified version which does the same as above but .. well,
simplified :P

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) { // if isset or !empty, the script would have been
exited cleanly.
ini_set('memory_limit','16M'); // This would be just to have enough
memory to print out the error.
echo 'h5-- BEGIN ERROR --/h5Error Ndeg;:
strong'.$errno.'/strongbr /Error Description:
strong'.$errstr.'/strongbr /File: strong'.$errfile.'/strongbr
/Line: strong'.$errline.'/strong';
if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
WHAT SHOULD IT RETURN?/p'; // isset or empty gives the same error
echo 'h5-- END ERROR --/h5';
die(); // shutdown_function == manual die() or else it will continue to
execute.
  }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  15000; $i++) $a[$i] = mt_rand(1,255);
$r['print'] = (string)$a[1]; // Just to asign something to that variable.
echo 'pEverything fine./p';
$clean_exit = TRUE;

Greetings :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/