@@ -426,18 +426,39 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **p
426
426
}
427
427
/* }}} */
428
428
429
- static ZEND_COLD bool zend_null_arg_deprecated (const char * type ) {
429
+ static ZEND_COLD bool zend_null_arg_deprecated (const char * fallback_type , uint32_t arg_num ) {
430
+ zend_function * func = EG (current_execute_data )-> func ;
431
+ ZEND_ASSERT (arg_num > 0 );
432
+ uint32_t arg_offset = arg_num - 1 ;
433
+ if (arg_offset >= func -> common .num_args ) {
434
+ ZEND_ASSERT (func -> common .fn_flags & ZEND_ACC_VARIADIC );
435
+ arg_offset = func -> common .num_args ;
436
+ }
437
+
438
+ zend_arg_info * arg_info = & func -> common .arg_info [arg_offset ];
430
439
zend_string * func_name = get_active_function_or_method_name ();
431
- zend_error (E_DEPRECATED , "%s(): Passing null to parameter of type %s is deprecated" ,
432
- ZSTR_VAL (func_name ), type );
440
+ const char * arg_name = get_active_function_arg_name (arg_num );
441
+
442
+ /* If no type is specified in arginfo, use the specified fallback_type determined through
443
+ * zend_parse_parameters instead. */
444
+ zend_string * type_str = zend_type_to_string (arg_info -> type );
445
+ const char * type = type_str ? ZSTR_VAL (type_str ) : fallback_type ;
446
+ zend_error (E_DEPRECATED ,
447
+ "%s(): Passing null to parameter #%" PRIu32 "%s%s%s of type %s is deprecated" ,
448
+ ZSTR_VAL (func_name ), arg_num ,
449
+ arg_name ? " ($" : "" , arg_name ? arg_name : "" , arg_name ? ")" : "" ,
450
+ type );
433
451
zend_string_release (func_name );
452
+ if (type_str ) {
453
+ zend_string_release (type_str );
454
+ }
434
455
return !EG (exception );
435
456
}
436
457
437
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak (zval * arg , bool * dest ) /* {{{ */
458
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak (zval * arg , bool * dest , uint32_t arg_num ) /* {{{ */
438
459
{
439
460
if (EXPECTED (Z_TYPE_P (arg ) <= IS_STRING )) {
440
- if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("bool" )) {
461
+ if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("bool" , arg_num )) {
441
462
return 0 ;
442
463
}
443
464
* dest = zend_is_true (arg );
@@ -448,16 +469,16 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest) /* {
448
469
}
449
470
/* }}} */
450
471
451
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_slow (zval * arg , bool * dest ) /* {{{ */
472
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_slow (zval * arg , bool * dest , uint32_t arg_num ) /* {{{ */
452
473
{
453
474
if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
454
475
return 0 ;
455
476
}
456
- return zend_parse_arg_bool_weak (arg , dest );
477
+ return zend_parse_arg_bool_weak (arg , dest , arg_num );
457
478
}
458
479
/* }}} */
459
480
460
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak (zval * arg , zend_long * dest ) /* {{{ */
481
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak (zval * arg , zend_long * dest , uint32_t arg_num ) /* {{{ */
461
482
{
462
483
if (EXPECTED (Z_TYPE_P (arg ) == IS_DOUBLE )) {
463
484
if (UNEXPECTED (zend_isnan (Z_DVAL_P (arg )))) {
@@ -490,7 +511,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest)
490
511
return 0 ;
491
512
}
492
513
} else if (EXPECTED (Z_TYPE_P (arg ) < IS_TRUE )) {
493
- if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("int" )) {
514
+ if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("int" , arg_num )) {
494
515
return 0 ;
495
516
}
496
517
* dest = 0 ;
@@ -503,16 +524,16 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest)
503
524
}
504
525
/* }}} */
505
526
506
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow (zval * arg , zend_long * dest ) /* {{{ */
527
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow (zval * arg , zend_long * dest , uint32_t arg_num ) /* {{{ */
507
528
{
508
529
if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
509
530
return 0 ;
510
531
}
511
- return zend_parse_arg_long_weak (arg , dest );
532
+ return zend_parse_arg_long_weak (arg , dest , arg_num );
512
533
}
513
534
/* }}} */
514
535
515
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak (zval * arg , double * dest ) /* {{{ */
536
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak (zval * arg , double * dest , uint32_t arg_num ) /* {{{ */
516
537
{
517
538
if (EXPECTED (Z_TYPE_P (arg ) == IS_LONG )) {
518
539
* dest = (double )Z_LVAL_P (arg );
@@ -531,7 +552,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest)
531
552
return 0 ;
532
553
}
533
554
} else if (EXPECTED (Z_TYPE_P (arg ) < IS_TRUE )) {
534
- if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("float" )) {
555
+ if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("float" , arg_num )) {
535
556
return 0 ;
536
557
}
537
558
* dest = 0.0 ;
@@ -544,19 +565,19 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest)
544
565
}
545
566
/* }}} */
546
567
547
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_slow (zval * arg , double * dest ) /* {{{ */
568
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_slow (zval * arg , double * dest , uint32_t arg_num ) /* {{{ */
548
569
{
549
570
if (EXPECTED (Z_TYPE_P (arg ) == IS_LONG )) {
550
571
/* SSTH Exception: IS_LONG may be accepted instead as IS_DOUBLE */
551
572
* dest = (double )Z_LVAL_P (arg );
552
573
} else if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
553
574
return 0 ;
554
575
}
555
- return zend_parse_arg_double_weak (arg , dest );
576
+ return zend_parse_arg_double_weak (arg , dest , arg_num );
556
577
}
557
578
/* }}} */
558
579
559
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow (zval * arg , zval * * dest ) /* {{{ */
580
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow (zval * arg , zval * * dest , uint32_t arg_num ) /* {{{ */
560
581
{
561
582
if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
562
583
return 0 ;
@@ -575,6 +596,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest) /
575
596
}
576
597
zend_string_release (str );
577
598
} else if (Z_TYPE_P (arg ) < IS_TRUE ) {
599
+ if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("int|float" , arg_num )) {
600
+ return 0 ;
601
+ }
578
602
ZVAL_LONG (arg , 0 );
579
603
} else if (Z_TYPE_P (arg ) == IS_TRUE ) {
580
604
ZVAL_LONG (arg , 1 );
@@ -586,10 +610,10 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest) /
586
610
}
587
611
/* }}} */
588
612
589
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak (zval * arg , zend_string * * dest ) /* {{{ */
613
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak (zval * arg , zend_string * * dest , uint32_t arg_num ) /* {{{ */
590
614
{
591
615
if (EXPECTED (Z_TYPE_P (arg ) < IS_STRING )) {
592
- if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("string" )) {
616
+ if (UNEXPECTED (Z_TYPE_P (arg ) == IS_NULL ) && !zend_null_arg_deprecated ("string" , arg_num )) {
593
617
return 0 ;
594
618
}
595
619
convert_to_string (arg );
@@ -611,24 +635,24 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **des
611
635
}
612
636
/* }}} */
613
637
614
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_slow (zval * arg , zend_string * * dest ) /* {{{ */
638
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_slow (zval * arg , zend_string * * dest , uint32_t arg_num ) /* {{{ */
615
639
{
616
640
if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
617
641
return 0 ;
618
642
}
619
- return zend_parse_arg_str_weak (arg , dest );
643
+ return zend_parse_arg_str_weak (arg , dest , arg_num );
620
644
}
621
645
/* }}} */
622
646
623
- ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow (zval * arg , zend_string * * dest_str , zend_long * dest_long ) /* {{{ */
647
+ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow (zval * arg , zend_string * * dest_str , zend_long * dest_long , uint32_t arg_num ) /* {{{ */
624
648
{
625
649
if (UNEXPECTED (ZEND_ARG_USES_STRICT_TYPES ())) {
626
650
return 0 ;
627
651
}
628
- if (zend_parse_arg_long_weak (arg , dest_long )) {
652
+ if (zend_parse_arg_long_weak (arg , dest_long , arg_num )) {
629
653
* dest_str = NULL ;
630
654
return 1 ;
631
- } else if (zend_parse_arg_str_weak (arg , dest_str )) {
655
+ } else if (zend_parse_arg_str_weak (arg , dest_str , arg_num )) {
632
656
* dest_long = 0 ;
633
657
return 1 ;
634
658
} else {
@@ -637,7 +661,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_stri
637
661
}
638
662
/* }}} */
639
663
640
- static const char * zend_parse_arg_impl (zval * arg , va_list * va , const char * * spec , char * * error ) /* {{{ */
664
+ static const char * zend_parse_arg_impl (zval * arg , va_list * va , const char * * spec , char * * error , uint32_t arg_num ) /* {{{ */
641
665
{
642
666
const char * spec_walk = * spec ;
643
667
char c = * spec_walk ++ ;
@@ -670,7 +694,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
670
694
is_null = va_arg (* va , bool * );
671
695
}
672
696
673
- if (!zend_parse_arg_long (arg , p , is_null , check_null )) {
697
+ if (!zend_parse_arg_long (arg , p , is_null , check_null , arg_num )) {
674
698
return check_null ? "?int" : "int" ;
675
699
}
676
700
}
@@ -685,7 +709,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
685
709
is_null = va_arg (* va , bool * );
686
710
}
687
711
688
- if (!zend_parse_arg_double (arg , p , is_null , check_null )) {
712
+ if (!zend_parse_arg_double (arg , p , is_null , check_null , arg_num )) {
689
713
return check_null ? "?float" : "float" ;
690
714
}
691
715
}
@@ -695,7 +719,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
695
719
{
696
720
zval * * p = va_arg (* va , zval * * );
697
721
698
- if (!zend_parse_arg_number (arg , p , check_null )) {
722
+ if (!zend_parse_arg_number (arg , p , check_null , arg_num )) {
699
723
return check_null ? "int|float|null" : "int|float" ;
700
724
}
701
725
}
@@ -705,7 +729,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
705
729
{
706
730
char * * p = va_arg (* va , char * * );
707
731
size_t * pl = va_arg (* va , size_t * );
708
- if (!zend_parse_arg_string (arg , p , pl , check_null )) {
732
+ if (!zend_parse_arg_string (arg , p , pl , check_null , arg_num )) {
709
733
return check_null ? "?string" : "string" ;
710
734
}
711
735
}
@@ -715,7 +739,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
715
739
{
716
740
char * * p = va_arg (* va , char * * );
717
741
size_t * pl = va_arg (* va , size_t * );
718
- if (!zend_parse_arg_path (arg , p , pl , check_null )) {
742
+ if (!zend_parse_arg_path (arg , p , pl , check_null , arg_num )) {
719
743
if (Z_TYPE_P (arg ) == IS_STRING ) {
720
744
zend_spprintf (error , 0 , "must not contain any null bytes" );
721
745
return "" ;
@@ -729,7 +753,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
729
753
case 'P' :
730
754
{
731
755
zend_string * * str = va_arg (* va , zend_string * * );
732
- if (!zend_parse_arg_path_str (arg , str , check_null )) {
756
+ if (!zend_parse_arg_path_str (arg , str , check_null , arg_num )) {
733
757
if (Z_TYPE_P (arg ) == IS_STRING ) {
734
758
zend_spprintf (error , 0 , "must not contain any null bytes" );
735
759
return "" ;
@@ -743,7 +767,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
743
767
case 'S' :
744
768
{
745
769
zend_string * * str = va_arg (* va , zend_string * * );
746
- if (!zend_parse_arg_str (arg , str , check_null )) {
770
+ if (!zend_parse_arg_str (arg , str , check_null , arg_num )) {
747
771
return check_null ? "?string" : "string" ;
748
772
}
749
773
}
@@ -758,7 +782,7 @@ static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec
758
782
is_null = va_arg (* va , bool * );
759
783
}
760
784
761
- if (!zend_parse_arg_bool (arg , p , is_null , check_null )) {
785
+ if (!zend_parse_arg_bool (arg , p , is_null , check_null , arg_num )) {
762
786
return check_null ? "?bool" : "bool" ;
763
787
}
764
788
}
@@ -919,7 +943,7 @@ static zend_result zend_parse_arg(uint32_t arg_num, zval *arg, va_list *va, cons
919
943
const char * expected_type = NULL ;
920
944
char * error = NULL ;
921
945
922
- expected_type = zend_parse_arg_impl (arg , va , spec , & error );
946
+ expected_type = zend_parse_arg_impl (arg , va , spec , & error , arg_num );
923
947
if (expected_type ) {
924
948
if (EG (exception )) {
925
949
return FAILURE ;
0 commit comments