@@ -2308,13 +2308,28 @@ inline int zend_check_private(zend_execute_data *execute_data, zend_class_entry
2308
2308
2309
2309
/* Ensures that we're allowed to call a protected method.
2310
2310
*/
2311
- inline int zend_check_protected (zend_class_entry * ce , zend_class_entry * scope , int fn_flags )
2311
+ inline int zend_check_protected (zend_class_entry * ce , zend_class_entry * scope )
2312
2312
{
2313
- while (ce ) {
2314
- if (ce == scope ) {
2313
+ zend_class_entry * fbc_scope = ce ;
2314
+
2315
+ /* Is the context that's calling the function, the same as one of
2316
+ * the function's parents?
2317
+ */
2318
+ while (fbc_scope ) {
2319
+ if (fbc_scope == scope ) {
2315
2320
return 1 ;
2316
2321
}
2317
- ce = ce -> parent ;
2322
+ fbc_scope = fbc_scope -> parent ;
2323
+ }
2324
+
2325
+ /* Is the function's scope the same as our current object context,
2326
+ * or any of the parents of our context?
2327
+ */
2328
+ while (scope ) {
2329
+ if (scope == ce ) {
2330
+ return 1 ;
2331
+ }
2332
+ scope = scope -> parent ;
2318
2333
}
2319
2334
return 0 ;
2320
2335
}
@@ -2355,7 +2370,7 @@ int zend_init_ctor_call_handler(ZEND_OPCODE_HANDLER_ARGS)
2355
2370
} else if ((EX (fbc )-> common .fn_flags & ZEND_ACC_PROTECTED )) {
2356
2371
/* Ensure that if we're calling a protected function, we're allowed to do so.
2357
2372
*/
2358
- if (!zend_check_protected (EG ( scope ), EX (fbc )-> common .scope , EX ( fbc ) -> common . fn_flags )) {
2373
+ if (!zend_check_protected (EX (fbc )-> common .scope , EG ( scope ) )) {
2359
2374
zend_error (E_ERROR , "Call to protected constructor from context '%s'" , EG (scope ) ? EG (scope )-> name : "" );
2360
2375
}
2361
2376
}
@@ -2416,7 +2431,7 @@ int zend_init_method_call_handler(ZEND_OPCODE_HANDLER_ARGS)
2416
2431
} else if ((EX (fbc )-> common .fn_flags & ZEND_ACC_PROTECTED )) {
2417
2432
/* Ensure that if we're calling a protected function, we're allowed to do so.
2418
2433
*/
2419
- if (!zend_check_protected (EG ( scope ), EX (fbc )-> common .scope , EX ( fbc ) -> common . fn_flags )) {
2434
+ if (!zend_check_protected (EX (fbc )-> common .scope , EG ( scope ) )) {
2420
2435
zend_error (E_ERROR , "Call to %s method %s::%s() from context '%s'" , zend_visibility_string (EX (fbc )-> common .fn_flags ), ZEND_FN_SCOPE_NAME (EX (fbc )), function_name_strval , EG (scope ) ? EG (scope )-> name : "" );
2421
2436
}
2422
2437
}
@@ -2498,7 +2513,7 @@ int zend_init_static_method_call_handler(ZEND_OPCODE_HANDLER_ARGS)
2498
2513
} else if ((EX (fbc )-> common .fn_flags & ZEND_ACC_PROTECTED )) {
2499
2514
/* Ensure that if we're calling a protected function, we're allowed to do so.
2500
2515
*/
2501
- if (!zend_check_protected (EG (scope ), EX (fbc )-> common .scope , EX ( fbc ) -> common . fn_flags )) {
2516
+ if (!zend_check_protected (EG (scope ), EX (fbc )-> common .scope )) {
2502
2517
zend_error (E_ERROR , "Call to %s method %s::%s() from context '%s'" , zend_visibility_string (EX (fbc )-> common .fn_flags ), ZEND_FN_SCOPE_NAME (EX (fbc )), function_name_strval , EG (scope ) ? EG (scope )-> name : "" );
2503
2518
}
2504
2519
}
0 commit comments