PHP 4.0 Bug #6741 Updated: gettype of 'user function' returns null
| From: | ping at alt dot it | Date: | Thu, 19 Oct 2000 16:05:03 +0000 |
| Subject: | PHP 4.0 Bug #6741 Updated: gettype of 'user function' returns null | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-35544@lists.php.net to get a copy of this message | ||
ID: 6741
User Update by: ping@alt.it
Status: Analyzed
Bug Type: Documentation problem
Description: gettype of 'user function' returns null
It was not me who invented this function, although I've been using it since 3.12.
It is quite useful for marshallizing and serializing things, and it gives a bit of introspection to
PHP.
And as in PHP4 the developers have thought to increase the scope of gettype() to new types as
'properties', which are still a bit of a mystery, I thought the old ones would still work.
Nevertheless $myclass->b in the esample above is an integer variable, better said an 'object
property', and not a string (PHP3) nor NULL (PHP4).
Previous Comments:
---------------------------------------------------------------------------
[2000-10-18 06:07:59] stas@php.net
What should be working? Function is not a variable, what type do you expect to get from there? Do
you want PHP also to return gettype($if) as "PHP language construct" and
gettype($Bill_Clinton) as "US president"? gettype returns types of variables, that's
it - it can not return type of whatever object that is not a variable.
---------------------------------------------------------------------------
[2000-10-15 11:28:15] jmoore@php.net
I would not say this is a docu problem but a scripting engine problem, This behaviour should really
be working, I dont think the docu's should be changed just because it doesnt, instead it should
be fixed.
James
---------------------------------------------------------------------------
[2000-09-25 20:34:08] ping@alt.it
more examples:
<?
$z=33;
function normal()
{
$a=1;
}
class class1
{
function classfunction1()
{
$b=2;
}
}
$myclass=new class1;
echo "myfunction is of type ",
gettype($myclass->classfunction1),"<br>n";
echo "b is of type ", gettype($myclass->b),"<br>n";
echo "z is of type ", gettype($z),"<br>n";
echo "normal is of type ", gettype($normal),"<br>n";
echo "class1 is of type ", gettype($class1),"<br>n";
echo "myclass is of type ", gettype($myclass),"<br>n";
echo "classfunction1 is of type ", gettype($classfunction1),"<br>n";
?>
this piece of code, run both on PHP 3.0.12 and PHP 4.0.2 gives these different results:
ouput by PHP 3 .0.12:
myfunction is of type user function
b is of type string
z is of type integer
normal is of type string
class1 is of type string
myclass is of type object
classfunction1 is of type string
output by PHP 4.02:
myfunction is of type NULL
b is of type NULL
z is of type integer
normal is of type NULL
class1 is of type NULL
myclass is of type object
classfunction1 is of type NULL
---------------------------------------------------------------------------
[2000-09-25 16:41:48] ping@alt.it
The doc at http://www.php.net/manual/function.gettype.php
says:
> gettype -- Get the type of a variable
> Description
> string gettype (mixed var)
> Returns the type of the PHP variable var.
> Possibles values for the returned string are:
> "boolean"
> "integer"
> "double"
> "string"
> "array"
> "object"
> "resource"
> "user function"
> "unknown type"
I wonder what happens with other types as 'object' or 'resource'
Anyway the string 'NULL' doesn't seem to be among the possible returned values.
---------------------------------------------------------------------------
[2000-09-23 22:26:27] stas@php.net
I don't see any mention in the manual that gettype should work on functions - only on
variables. In fact, it cannot veen return "user function" now, so I put it in doc's
problem.
---------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view the rest of the comments,
please view the bug report online.
Full Bug description available at: http://bugs.php.net/?id=6741