Skip to content

Commit 01049ca

Browse files
committed
Fixed bug #61025 (__invoke() visibility not honored)
1 parent ac73ca6 commit 01049ca

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
07 Mar 2013, PHP 5.5.0 Alpha 6
77

88
- Core:
9+
. Fixed bug #61025 (__invoke() visibility not honored). (Laruence)
910
. Fixed bug #49348 (Uninitialized ++$foo->bar; does not cause a notice).
1011
(Stas)
1112

NEWS-5.5

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? 201?, PHP 5.5.0 Beta 1
44

55
- Core:
6+
. Fixed bug #61025 (__invoke() visibility not honored). (Laruence)
67
. Fixed bug #49348 (Uninitialized ++$foo->bar; does not cause a notice).
78
(Stas)
89

Zend/tests/bug61025.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #61025 (__invoke() visibility not honored)
3+
--FILE--
4+
<?php
5+
6+
Interface InvokeAble {
7+
static function __invoke();
8+
}
9+
10+
class Bar {
11+
private function __invoke() {
12+
return __CLASS__;
13+
}
14+
}
15+
16+
$b = new Bar;
17+
echo $b();
18+
19+
echo $b->__invoke();
20+
21+
?>
22+
--EXPECTF--
23+
Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
24+
25+
Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
26+
Bar
27+
Fatal error: Call to private method Bar::__invoke() from context '' in %sbug61025.php on line %d

Zend/zend_closures.c

-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ static zend_object_value zend_closure_clone(zval *zobject TSRMLS_DC) /* {{{ */
291291
}
292292
/* }}} */
293293

294-
295294
int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
296295
{
297296
zend_closure *closure;

Zend/zend_closures.h

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
BEGIN_EXTERN_C()
2626

27-
#define ZEND_INVOKE_FUNC_NAME "__invoke"
28-
2927
void zend_register_closure_ce(TSRMLS_D);
3028

3129
extern ZEND_API zend_class_entry *zend_ce_closure;

Zend/zend_compile.c

+8
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,10 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
16211621
if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
16221622
zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static");
16231623
}
1624+
} else if ((name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) {
1625+
if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
1626+
zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static");
1627+
}
16241628
}
16251629
} else {
16261630
char *class_lcname;
@@ -1677,6 +1681,10 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
16771681
zend_error(E_WARNING, "The magic method __toString() must have public visibility and cannot be static");
16781682
}
16791683
CG(active_class_entry)->__tostring = (zend_function *) CG(active_op_array);
1684+
} else if ((name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1))) {
1685+
if (fn_flags & ((ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
1686+
zend_error(E_WARNING, "The magic method __invoke() must have public visibility and cannot be static");
1687+
}
16801688
} else if (!(fn_flags & ZEND_ACC_STATIC)) {
16811689
CG(active_op_array)->fn_flags |= ZEND_ACC_ALLOW_STATIC;
16821690
}

Zend/zend_compile.h

+1
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ END_EXTERN_C()
856856
#define ZEND_CALLSTATIC_FUNC_NAME "__callstatic"
857857
#define ZEND_TOSTRING_FUNC_NAME "__tostring"
858858
#define ZEND_AUTOLOAD_FUNC_NAME "__autoload"
859+
#define ZEND_INVOKE_FUNC_NAME "__invoke"
859860

860861
/* The following constants may be combined in CG(compiler_options)
861862
* to change the default compiler behavior */

0 commit comments

Comments
 (0)