|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42412 addslashes() doesnot behave with NULL as documented
Submitted: 2007-08-24 12:05 UTC Modified: 2007-08-24 13:05 UTC
From: nikhil dot gupta at in dot ibm dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5CVS-2007-08-24 (snap) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nikhil dot gupta at in dot ibm dot com
New email:
PHP Version: OS:


 [2007-08-24 12:05 UTC] nikhil dot gupta at in dot ibm dot com
As per the documentation, it should insert a backslash in the return string. But it returns an empty string without any backslash.

Reproduce code:
  var_dump( NULL);
  var_dump( addslashes(NULL) );

Expected result:
string(1) "\"

Actual result:
string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-24 12:20 UTC]
You misunderstood the documentation, it's about the NUL character, not about NULL in PHP land.
 [2007-08-24 12:34 UTC] 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 13:05 UTC]
Try this instead:

$txt = '-'.chr(0).'-';
var_dump($txt, addslashes($txt));

Output is:
string(3) "--"
string(4) "-\0-"

NUL is something you don't see. :)

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 05:01:35 2024 UTC