php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41546 Is_callable() function behavior incorrect in PHP5.
Submitted: 2007-05-31 06:29 UTC Modified: 2007-06-05 10:03 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: mahesh dot vemula at in dot ibm dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.2.2 OS: RHEL4
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mahesh dot vemula at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-05-31 06:29 UTC] mahesh dot vemula at in dot ibm dot com
Description:
------------
In the below testcode, PHP5 & PHP6 outputs differ for is_callable() function.
In PHP6 when we are echo-ing a string( eg. "welcome\0" ) with null character at the end of the string, the output with run-tests shows null character also at the end of the string.
Whereas, running the file with php5.2.2 gives the expected output ( i.e "welcome").

is_callable() function in PHP 5 is incorrectly truncating the name passed when it calls ZVAL_STRING,  i.e it should be possible to have function names with embedded nulls.
The behavior on PHP6 looks be correct.
This is consistent with the expected behaviour after reading Sarah Goleman's book; page 25. It says: 
 "What's worth noting about PHP string is that the length of the string is always explicitly stated in the zval structure. This allows strings to contain NULL bytes without being truncated. This aspect of PHP strings will be referred to hereafter as binary safety because it makes it safe to contain any type of binary data."

Reproduce code:
---------------
<?php
$undef_functions = array (
  "\0",
  '\0',
  "welcome\0",
  'welcome\0',
);
$counter = 1;
foreach($undef_functions as $func) {
echo "-- Iteration  $counter --\n";
var_dump( is_callable($func, FALSE, $callable_name) );
echo $callable_name, "\n";
$counter++;
}
echo "done";

?>

Expected result:
----------------
-- Iteration  1 --
bool(false)
_
-- Iteration  2 --
bool(false)
\0
-- Iteration  3 --
bool(false)
welcome_
-- Iteration  4 --
bool(false)
welcome\0
done

Actual result:
--------------
-- Iteration  1 --
bool(false)

-- Iteration  2 --
bool(false)
\0
-- Iteration  3 --
bool(false)
welcome
-- Iteration  4 --
bool(false)
welcome\0
done

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-31 21:44 UTC] tony2001@php.net
>is_callable() function in PHP 5 is incorrectly truncating the name
passed when it calls ZVAL_STRING

Well, the problem is that zend_is_callable() in PHP5 operates on strings, not zvals (like in PHP6, which is just a sideffect of having two types of strings), so there is no way to know the length of the resulting string except to use strlen().

>i.e it should be possible to have function names with embedded nulls.

Functions with embedded nulls make no sense to me.

So the bottom line is:
function names with NULLs are not supported in both PHP5 and PHP6, but PHP6 just happens to handle them correctly.
I'd say this is a "won't fix".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC