Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Zend/tests/is_a_string.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
is_a() with $allow_string false and a string
--FILE--
<?php

class Demo {}

var_dump(is_a(Demo::class, Demo::class, true));
var_dump(is_a(Demo::class, Demo::class, false));

?>
--EXPECTF--
bool(true)

Deprecated: Calling is_a() with a string when $allow_string is false in %s on line %d
bool(false)
18 changes: 18 additions & 0 deletions Zend/tests/is_subclass_of_string.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
is_subclass_of() with $allow_string false and a string
--FILE--
<?php

class Demo {}

class Child extends Demo {}

var_dump(is_subclass_of(Child::class, Demo::class, true));
var_dump(is_subclass_of(Child::class, Demo::class, false));

?>
--EXPECTF--
bool(true)

Deprecated: Calling is_subclass_of() with a string when $allow_string is false in %s on line %d
bool(false)
12 changes: 12 additions & 0 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,18 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, bool only_subclass) /* {{{ *
if (!instance_ce) {
RETURN_FALSE;
}
} else if (Z_TYPE_P(obj) == IS_STRING) {
// is_a() uses only_subclass as false, is_subclass_of() uses it as true
zend_error(
E_DEPRECATED,
only_subclass
? "Calling is_subclass_of() with a string when $allow_string is false"
: "Calling is_a() with a string when $allow_string is false"
);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
RETURN_FALSE;
} else if (Z_TYPE_P(obj) == IS_OBJECT) {
instance_ce = Z_OBJCE_P(obj);
} else {
Expand Down
Loading