php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #6741 gettype of 'user function' returns null
Submitted: 2000-09-13 19:16 UTC Modified: 2000-11-03 00:01 UTC
From: ping at alt dot it Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.2 OS: Linux Mandrake 7.0
Private report: No CVE-ID: None
 [2000-09-13 19:16 UTC] ping at alt dot it
gettype() on function names returns null

Although undocumented, in version 3 it properly returned 'user function'.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-16 18:21 UTC] stas@php.net
Please provide a code example.
Also, I guess you should never rely on undocumented behaviour to preserve, anyway.
 [2000-09-20 05:23 UTC] ping at alt dot it
It WAS undocumented but  working on php3.
It IS documented and doesn't work on php4


<?
class class1
{
function classfunction1()
  {
  $b=2;
  }
}
$myclass=new class1;
echo "classfunction1 is of type ", gettype($myclass->classfunction1),"<br>\n";
?>  
 [2000-09-23 22:26 UTC] 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.
 [2000-09-25 16:41 UTC] ping at alt dot 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-25 20:34 UTC] ping at alt dot 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-10-15 11:28 UTC] 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-10-18 06:07 UTC] 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-19 12:05 UTC] ping at alt dot it
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).


 [2000-10-22 12:27 UTC] ping at alt dot it
This missing functionality actually breaks the PHP 'remote scripting' interface, as discussed some time ago in the php mailing list

See messages about 'remote scripting' starting at
http://marc.theaimsgroup.com/?l=php-general&m=92113045423518&w=2
 [2000-10-23 04:53 UTC] ping at alt dot it
This bug now can be circumvented by using the new 
method_exixts() functionof PHP4.

It is only viable for class methods though.

I think that for backward compatibility, and to keep in line with the old and new documentation, it shouldn't be too hard to have gettype() return 'user function' too.

Otherwise relegate it as a docu error and thanks for the help

Meanwile I posted a new version of the php4 implementation of 'remote scripting' that uses 'method_exixts()? instead on php-general list and am awaitimg a feedback from the original author. 
 [2000-10-23 04:58 UTC] stas@php.net
This is not a bug. I repeat: This. Is. Not. A. Bug. gettype is meant to get type of a variable. Function is not a variable. Thus, you can not use gettype on a function. 
If you need to check existance of a function with given name, use function_exists.
 [2000-11-03 00:01 UTC] ronabop@php.net
Documented.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 06:00:01 2026 UTC