Skip to content

Commit cac1298

Browse files
author
Your Name
committed
Allow resolving class names with gettype
Adding blessed changes Replaced spaces with tabs Return zend_string without intern Returning copy of name
1 parent 4cbffd8 commit cac1298

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ function stream_set_timeout($socket, int $seconds, int $microseconds = 0): bool
13151315
/* type.c */
13161316

13171317
/** @param mixed $var */
1318-
function gettype($var): string {}
1318+
function gettype($var, bool $resolve_object_names = false): string {}
13191319

13201320
function settype(&$var, string $type): bool {}
13211321

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ ZEND_END_ARG_INFO()
20082008

20092009
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gettype, 0, 1, IS_STRING, 0)
20102010
ZEND_ARG_INFO(0, var)
2011+
ZEND_ARG_TYPE_INFO(0, resolve_object_names, _IS_BOOL, 0)
20112012
ZEND_END_ARG_INFO()
20122013

20132014
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_settype, 0, 2, _IS_BOOL, 0)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test gettype() class reading
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
8+
}
9+
10+
/* tests against an object type */
11+
echo gettype(new Test()) . "\n";
12+
echo gettype(new Test(), false) . "\n";
13+
echo gettype(new Test(), true) . "\n";
14+
15+
/* tests against everything else */
16+
echo gettype(1) . "\n";
17+
echo gettype(1.1) . "\n";
18+
echo gettype("foo") . "\n";
19+
echo gettype(Test::class) . "\n";
20+
21+
--EXPECT--
22+
object
23+
object
24+
Test
25+
integer
26+
double
27+
string
28+
string

ext/standard/type.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ PHP_FUNCTION(gettype)
2323
{
2424
zval *arg;
2525
zend_string *type;
26+
zend_bool resolve_object_names = 0;
2627

27-
ZEND_PARSE_PARAMETERS_START(1, 1)
28+
ZEND_PARSE_PARAMETERS_START(1, 2)
2829
Z_PARAM_ZVAL(arg)
30+
Z_PARAM_OPTIONAL
31+
Z_PARAM_BOOL(resolve_object_names)
2932
ZEND_PARSE_PARAMETERS_END();
3033

34+
if (resolve_object_names && Z_TYPE_P(arg) == IS_OBJECT) {
35+
RETURN_STR_COPY(Z_OBJ_P(arg)->ce->name);
36+
}
37+
3138
type = zend_zval_get_type(arg);
3239
if (EXPECTED(type)) {
3340
RETURN_INTERNED_STR(type);

0 commit comments

Comments
 (0)