#42412 [Opn->Bgs]: addslashes() doesnot behave with NULL as documented

From: Date: Fri, 24 Aug 2007 13:05:16 +0000
Subject: #42412 [Opn->Bgs]: addslashes() doesnot behave with NULL as documented
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116627@lists.php.net to get a copy of this message
ID: 42412 Updated by: jani@php.net Reported By: nikhil dot gupta at in dot ibm dot com -Status: Open +Status: Bogus Bug Type: Strings related Operating System: Linux PHP Version: 5CVS-2007-08-24 (snap) New Comment: Try this instead: <?php $txt = '-'.chr(0).'-'; var_dump($txt, addslashes($txt)); ?> Output is: string(3) "--" string(4) "-\0-" NUL is something you don't see. :) Previous Comments: ------------------------------------------------------------------------ [2007-08-24 12:34:52] nikhil dot gupta at in dot ibm dot com Thankyou for correcting me. I tried with NUL character (\0) also. Is following the expected output? var_dump( addslashes("abc\0abc") ); The output I get is: string(8) "abc\0abc" OR should it be: string(8) "abc\abc" (here a backslash is added before NUL) OR should it be: string(8) "abc\\0abc" I think here the output should be: string(8) "abc\\0abc" because here the NUL is preceded with backslash character and also the length of string is 8. ------------------------------------------------------------------------ [2007-08-24 12:20:22] jani@php.net You misunderstood the documentation, it's about the NUL character, not about NULL in PHP land. ------------------------------------------------------------------------ [2007-08-24 12:05:12] nikhil dot gupta at in dot ibm dot com Description: ------------ As per the documentation, it should insert a backslash in the return string. But it returns an empty string without any backslash. Reproduce code: --------------- <?php var_dump( NULL); var_dump( addslashes(NULL) ); ?> Expected result: ---------------- NULL string(1) "\" Actual result: -------------- NULL string(0) "" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42412&edit=1

« previous php.bugs (#116627) next »