@@ -357,6 +357,7 @@ interface FunctionOrMethodName {
357
357
public function getDeclaration (): string ;
358
358
public function getArgInfoName (): string ;
359
359
public function __toString (): string ;
360
+ public function isMagicMethod (): bool ;
360
361
}
361
362
362
363
class FunctionName implements FunctionOrMethodName {
@@ -374,19 +375,19 @@ public function getNamespace(): ?string {
374
375
return null ;
375
376
}
376
377
377
- public function getShortName (): string {
378
- return $ this ->name ->getLast ();
379
- }
380
-
381
378
public function getNonNamespacedName (): string {
382
379
if ($ this ->name ->isQualified ()) {
383
380
throw new Exception ("Namespaced name not supported here " );
384
381
}
385
382
return $ this ->name ->toString ();
386
383
}
387
384
385
+ public function getDeclarationName (): string {
386
+ return $ this ->name ->getLast ();
387
+ }
388
+
388
389
public function getDeclaration (): string {
389
- return "ZEND_FUNCTION( {$ this ->name -> getLast ()}); \n" ;
390
+ return "ZEND_FUNCTION( {$ this ->getDeclarationName ()}); \n" ;
390
391
}
391
392
392
393
public function getArgInfoName (): string {
@@ -397,29 +398,41 @@ public function getArgInfoName(): string {
397
398
public function __toString (): string {
398
399
return $ this ->name ->toString ();
399
400
}
401
+
402
+ public function isMagicMethod (): bool {
403
+ return false ;
404
+ }
400
405
}
401
406
402
407
class MethodName implements FunctionOrMethodName {
408
+ /** @var Name */
409
+ private $ className ;
403
410
/** @var string */
404
- public $ className ;
405
- /** @var string */
406
- public $ name ;
411
+ public $ methodName ;
407
412
408
- public function __construct (string $ className , string $ name ) {
413
+ public function __construct (Name $ className , string $ methodName ) {
409
414
$ this ->className = $ className ;
410
- $ this ->name = $ name ;
415
+ $ this ->methodName = $ methodName ;
416
+ }
417
+
418
+ public function getDeclarationClassName (): string {
419
+ return implode ('_ ' , $ this ->className ->parts );
411
420
}
412
421
413
422
public function getDeclaration (): string {
414
- return "ZEND_METHOD( $ this ->className , $ this ->name ); \n" ;
423
+ return "ZEND_METHOD( { $ this ->getDeclarationClassName ()} , $ this ->methodName ); \n" ;
415
424
}
416
425
417
426
public function getArgInfoName (): string {
418
- return "arginfo_class_ {$ this ->className }_ {$ this ->name }" ;
427
+ return "arginfo_class_ {$ this ->getDeclarationClassName () }_ {$ this ->methodName }" ;
419
428
}
420
429
421
430
public function __toString (): string {
422
- return "$ this ->className :: $ this ->name " ;
431
+ return "$ this ->className :: $ this ->methodName " ;
432
+ }
433
+
434
+ public function isMagicMethod (): bool {
435
+ return strpos ($ this ->methodName , '__ ' ) === 0 ;
423
436
}
424
437
}
425
438
@@ -526,58 +539,63 @@ public function getFunctionEntry(): string {
526
539
if ($ this ->alias instanceof MethodName) {
527
540
return sprintf (
528
541
"\tZEND_MALIAS(%s, %s, %s, %s, %s) \n" ,
529
- $ this ->alias ->className , $ this ->name ->name , $ this ->alias ->name , $ this ->getArgInfoName (), $ this ->getFlagsAsString ()
542
+ $ this ->alias ->getDeclarationClassName (), $ this ->name ->methodName ,
543
+ $ this ->alias ->methodName , $ this ->getArgInfoName (), $ this ->getFlagsAsString ()
530
544
);
531
545
} else if ($ this ->alias instanceof FunctionName) {
532
546
return sprintf (
533
547
"\tZEND_ME_MAPPING(%s, %s, %s, %s) \n" ,
534
- $ this ->name ->name , $ this ->alias ->getNonNamespacedName (),
548
+ $ this ->name ->methodName , $ this ->alias ->getNonNamespacedName (),
535
549
$ this ->getArgInfoName (), $ this ->getFlagsAsString ()
536
550
);
537
551
} else {
538
552
throw new Error ("Cannot happen " );
539
553
}
540
554
} else {
555
+ $ declarationClassName = $ this ->name ->getDeclarationClassName ();
541
556
if ($ this ->flags & Class_::MODIFIER_ABSTRACT ) {
542
557
return sprintf (
543
558
"\tZEND_ABSTRACT_ME_WITH_FLAGS(%s, %s, %s, %s) \n" ,
544
- $ this ->name ->className , $ this ->name ->name , $ this ->getArgInfoName (), $ this ->getFlagsAsString ()
559
+ $ declarationClassName , $ this ->name ->methodName , $ this ->getArgInfoName (),
560
+ $ this ->getFlagsAsString ()
545
561
);
546
562
}
547
563
548
564
return sprintf (
549
565
"\tZEND_ME(%s, %s, %s, %s) \n" ,
550
- $ this ->name ->className , $ this ->name ->name , $ this ->getArgInfoName (), $ this ->getFlagsAsString ()
566
+ $ declarationClassName , $ this ->name ->methodName , $ this ->getArgInfoName (),
567
+ $ this ->getFlagsAsString ()
551
568
);
552
569
}
553
570
} else if ($ this ->name instanceof FunctionName) {
554
571
$ namespace = $ this ->name ->getNamespace ();
555
- $ shortName = $ this ->name ->getShortName ();
572
+ $ declarationName = $ this ->name ->getDeclarationName ();
556
573
557
574
if ($ this ->alias && $ this ->isDeprecated ) {
558
575
return sprintf (
559
576
"\tZEND_DEP_FALIAS(%s, %s, %s) \n" ,
560
- $ shortName , $ this ->alias ->getNonNamespacedName (), $ this ->getArgInfoName ()
577
+ $ declarationName , $ this ->alias ->getNonNamespacedName (), $ this ->getArgInfoName ()
561
578
);
562
579
}
563
580
564
581
if ($ this ->alias ) {
565
582
return sprintf (
566
583
"\tZEND_FALIAS(%s, %s, %s) \n" ,
567
- $ shortName , $ this ->alias ->getNonNamespacedName (), $ this ->getArgInfoName ()
584
+ $ declarationName , $ this ->alias ->getNonNamespacedName (), $ this ->getArgInfoName ()
568
585
);
569
586
}
570
587
571
588
if ($ this ->isDeprecated ) {
572
- return sprintf ("\tZEND_DEP_FE(%s, %s) \n" , $ shortName , $ this ->getArgInfoName ());
589
+ return sprintf (
590
+ "\tZEND_DEP_FE(%s, %s) \n" , $ declarationName , $ this ->getArgInfoName ());
573
591
}
574
592
575
593
if ($ namespace ) {
576
594
return sprintf (
577
595
"\tZEND_NS_FE( \"%s \", %s, %s) \n" ,
578
- $ namespace , $ shortName , $ this ->getArgInfoName ());
596
+ $ namespace , $ declarationName , $ this ->getArgInfoName ());
579
597
} else {
580
- return sprintf ("\tZEND_FE(%s, %s) \n" , $ shortName , $ this ->getArgInfoName ());
598
+ return sprintf ("\tZEND_FE(%s, %s) \n" , $ declarationName , $ this ->getArgInfoName ());
581
599
}
582
600
} else {
583
601
throw new Error ("Cannot happen " );
@@ -622,12 +640,12 @@ public function discardInfoForOldPhpVersions(): void {
622
640
}
623
641
624
642
class ClassInfo {
625
- /** @var string */
643
+ /** @var Name */
626
644
public $ name ;
627
645
/** @var FuncInfo[] */
628
646
public $ funcInfos ;
629
647
630
- public function __construct (string $ name , array $ funcInfos ) {
648
+ public function __construct (Name $ name , array $ funcInfos ) {
631
649
$ this ->name = $ name ;
632
650
$ this ->funcInfos = $ funcInfos ;
633
651
}
@@ -741,7 +759,7 @@ function parseFunctionLike(
741
759
if (count ($ aliasParts ) === 1 ) {
742
760
$ alias = new FunctionName (new Name ($ aliasParts [0 ]));
743
761
} else {
744
- $ alias = new MethodName ($ aliasParts [0 ], $ aliasParts [1 ]);
762
+ $ alias = new MethodName (new Name ( $ aliasParts [0 ]) , $ aliasParts [1 ]);
745
763
}
746
764
} else if ($ tag ->name === 'deprecated ' ) {
747
765
$ isDeprecated = true ;
@@ -814,7 +832,7 @@ function parseFunctionLike(
814
832
}
815
833
816
834
$ returnType = $ func ->getReturnType ();
817
- if ($ returnType === null && !$ haveDocReturnType && strpos ( $ name ->name , ' __ ' ) !== 0 ) {
835
+ if ($ returnType === null && !$ haveDocReturnType && ! $ name ->isMagicMethod () ) {
818
836
throw new Exception ("Missing return type for function $ name() " );
819
837
}
820
838
@@ -906,7 +924,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
906
924
}
907
925
908
926
if ($ stmt instanceof Stmt \ClassLike) {
909
- $ className = $ stmt ->name -> toString () ;
927
+ $ className = $ stmt ->namespacedName ;
910
928
$ methodInfos = [];
911
929
foreach ($ stmt ->stmts as $ classStmt ) {
912
930
$ cond = handlePreprocessorConditions ($ conds , $ classStmt );
@@ -1160,10 +1178,14 @@ function (FuncInfo $funcInfo) use($fileInfo, &$generatedFunctionDeclarations) {
1160
1178
}
1161
1179
1162
1180
/** @param FuncInfo[] $funcInfos */
1163
- function generateFunctionEntries (?string $ className , array $ funcInfos ): string {
1181
+ function generateFunctionEntries (?Name $ className , array $ funcInfos ): string {
1164
1182
$ code = "" ;
1165
1183
1166
- $ functionEntryName = $ className ? "class_ {$ className }_methods " : "ext_functions " ;
1184
+ $ functionEntryName = "ext_functions " ;
1185
+ if ($ className ) {
1186
+ $ underscoreName = implode ("_ " , $ className ->parts );
1187
+ $ functionEntryName = "class_ {$ underscoreName }_methods " ;
1188
+ }
1167
1189
1168
1190
$ code .= "\n\nstatic const zend_function_entry {$ functionEntryName }[] = { \n" ;
1169
1191
$ code .= generateCodeWithConditions ($ funcInfos , "" , function (FuncInfo $ funcInfo ) {
0 commit comments