-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ext_reflection_hni.php
2479 lines (2248 loc) · 72.3 KB
/
ext_reflection_hni.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?hh
/**
* ( excerpt from
* http://php.net/manual/en/class.reflectionfunctionabstract.php )
*
* A parent class to ReflectionFunction and ParentMethod. Read their
* descriptions for details.
*/
<<__NativeData('ReflectionFuncHandle')>>
abstract class ReflectionFunctionAbstract implements Reflector {
const IS_STATIC = 1;
const IS_PUBLIC = 256;
const IS_PROTECTED = 512;
const IS_PRIVATE = 1024;
const IS_ABSTRACT = 2;
const IS_FINAL = 4;
/**
* (excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getname.php )
*
* Get the name of the function. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return string The name of the function.
*/
<<__Native>>
public function getName(): string;
/**
* ( excerpt from http://php.net/manual/en/reflectionfunctionabstract.innamespace.php
* )
*
* Checks whether a function is defined in a namespace.
*
* @return bool Returns TRUE on success or FALSE on failure.
*/
public function inNamespace(): bool {
return strrpos($this->getName(), '\\') !== false;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getnamespacename.php )
*
* Get the namespace name where the function is defined.
*
* @return string The namespace name.
*/
public function getNamespaceName(): string {
$name = $this->getName();
$pos = strrpos($name, '\\');
return ($pos === false) ? '' : substr($name, 0, $pos);
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getshortname.php )
*
* Get the short name of the function (without the namespace part).
*
* @return string The short name of the function.
*/
public function getShortName(): string {
$name = $this->getName();
$pos = strrpos($name, '\\');
return ($pos === false) ? $name : substr($name, $pos + 1);
}
<<__Native, __HipHopSpecific>>
public function isHack(): bool;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isinternal.php )
*
* Checks whether the function is internal, as opposed to user-defined.
* Warning: This function is currently not documented; only its argument
* list is available.
*
* @return mixed TRUE if it's internal, otherwise FALSE
*/
<<__Native>>
public function isInternal(): bool;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isclosure.php )
*
* Checks whether it's a closure. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return bool TRUE if it's a closure, otherwise FALSE
*/
public function isClosure(): bool {
return false;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isgenerator.php )
*
* Warning: This function is currently not documented; only its argument
* list is available.
*
* @return bool TRUE if the function is generator, otherwise FALSE.
*/
<<__Native>>
public function isGenerator(): bool;
/**
* @return bool TRUE if the function is async, otherwise FALSE.
*/
<<__Native, __HipHopSpecific>>
public function isAsync(): bool;
/**
* Indicates whether the function has ...$varargs as its last parameter
* to capture variadic arguments.
*
* @return bool TRUE if the function is variadic, otherwise FALSE
*/
<<__Native>>
public function isVariadic(): bool;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isuserdefined.php )
*
* Checks whether the function is user-defined, as opposed to internal.
* Warning: This function is currently not documented; only its argument
* list is available.
*
* @return mixed TRUE if it's user-defined, otherwise false;
*/
public function isUserDefined(): bool {
return !$this->isInternal();
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getfilename.php )
*
* Gets the file name from a user-defined function. Warning: This function
* is currently not documented; only its argument list is available.
*
* @return mixed The file name.
*/
<<__Native>>
public function getFileName(): mixed;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getstartline.php )
*
* Gets the starting line number of the function. Warning: This function
* is currently not documented; only its argument list is available.
*
* @return mixed The starting line number.
*/
<<__Native>>
public function getStartLine(): mixed;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getendline.php )
*
* Get the ending line number. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed The ending line number of the user defined function,
* or FALSE if unknown.
*/
<<__Native>>
public function getEndLine(): mixed;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getdoccomment.php )
*
* Get a Doc comment from a function. Warning: This function is currently
* not documented; only its argument list is available.
*
* @return mixed The doc comment string if it exists, otherwise FALSE
*/
<<__Native>>
public function getDocComment(): mixed;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getstaticvariables.php
* )
*
* Get the static variables. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return array<string, mixed> An array of static variables.
*/
<<__Native>>
public function getStaticVariables(): array;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.returnsreference.php
* )
*
* Checks whether the function returns a reference. Warning: This function
* is currently not documented; only its argument list is available.
*
* @return mixed TRUE if it returns a reference, otherwise FALSE
*/
<<__Native>>
public function returnsReference(): bool;
<<__Native>>
private function getRetTypeInfo(): array;
<<__Native, __HipHopSpecific>>
private function getReturnTypeHint(): string;
<<__HipHopSpecific>>
public function getReturnTypeText() {
return $this->getReturnTypeHint() ?: false;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.hasreturntype.php
* )
*
* Checks if the function has a specified return type.
*
* @return - true if the function has a specified return type; false
* otherwise.
*/
public function hasReturnType(): bool {
return (bool) $this->getReturnTypeText();
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getReturnType.php
* )
*
* Gets the specified return type of a function
*
* @return - a ReflectionType object if a return type is specified; null
* otherwise.
*/
public function getReturnType(): ?ReflectionType {
if ($this->hasReturnType()) {
$retTypeInfo = $this->getRetTypeInfo();
return new ReflectionType(
$this,
array(
'name' => $retTypeInfo['type_hint'],
'nullable' => $retTypeInfo['type_hint_nullable'],
'builtin' => $retTypeInfo['type_hint_builtin'],
)
);
}
return null;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionclass.getattributes.php )
*
* Gets all attributes
*
* @return array<arraykey, array<int, mixed>>
*/
<<__Native>>
final public function getAttributes(): array;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionclass.getattribute.php )
*
* Returns all attributes with given key.
*
* @return ?array<int, mixed>
*/
final public function getAttribute(string $name) {
return hphp_array_idx($this->getAttributes(), $name, null);
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionclass.getattributes.php )
*
* Gets all attributes
*
* @return array<arraykey, array<int, mixed>>
*/
public function getAttributesRecursive(): array {
return $this->getAttributes();
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionclass.getattributerecursive.php
* )
*
* Returns all attributes with given key from a class and its parents.
*
* @return array<arraykey, array<int, mixed>>
*/
public function getAttributeRecursive($name) {
return $this->getAttribute($name);
}
<<__Native>>
public function getNumberOfParameters(): int;
<<__Native>>
private function getParamInfo(): array;
private $params = null;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getparameters.php )
*
* Get the parameters as an array of ReflectionParameter. Warning: This
* function is currently not documented; only its argument list is
* available.
*
* @return array The parameters, as a ReflectionParameter object.
*/
public function getParameters(): array<ReflectionParameter> {
// FIXME: ReflectionParameter sh/could have native data pointing to the
// relevant Func::ParamInfo data structure
if (null === $this->params) {
$ret = array();
foreach ($this->getParamInfo() as $name => $info) {
$param = new ReflectionParameter(null, null);
$param->info = $info;
$param->name = $info['name'];
$param->paramTypeInfo = array();
$param->paramTypeInfo['name'] = $info['type_hint'];
$param->paramTypeInfo['nullable'] = $info['type_hint_nullable'];
$param->paramTypeInfo['builtin'] = $info['type_hint_builtin'];
$ret[] = $param;
}
$this->params = $ret;
}
return $this->params;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getnumberofrequiredparameters.php
* )
*
* Get the number of required parameters that a function defines. Warning:
* This function is currently not documented; only its argument list is
* available.
*
* @return mixed The number of required parameters.
*/
public function getNumberOfRequiredParameters() {
$count = 0;
$params = $this->getParameters();
foreach ($params as $name => $param) {
if ($param->isOptional()) {
break;
}
$count++;
}
return $count;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isdeprecated.php
* )
*
* Returns whether the function is deprecated.
*/
public function isDeprecated(): bool {
return null !== $this->getAttribute('__Deprecated');
}
public function getExtension() {
// FIXME: HHVM doesn't support this
return null;
}
public function getExtensionName() {
return null;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getclosurescopeclass.php
* )
*
* Returns the scope associated to the closure
*
* @return mixed Returns the class on success or NULL on failure.
*/
public function getClosureScopeClass(): ?ReflectionClass {
return null;
}
// Prevent cloning
final public function __clone() {
throw new BadMethodCallException(
'Trying to clone an uncloneable object of class ' . get_class($this)
);
}
// Implementation of __toString
final protected function __toStringHelper(
$type,
array $preAttrs = [],
array $funcAttrs = [],
): string {
$ret = '';
if ($doc = $this->getDocComment()) {
$ret .= $doc . "\n";
}
$ret .= "$type [ <";
if ($this->isInternal()) {
$ret .= 'internal';
if ($this->isDeprecated()) {
$ret .= ', deprecated';
}
if ($extensionName = $this->getExtensionName()) {
$ret .= ':' . $extensionName;
}
} else {
$ret .= 'user';
}
if ($preAttrs) {
$ret .= ', ' . implode(', ', $preAttrs);
}
$ret .= '> ';
if ($funcAttrs) {
$ret .= implode(' ', $funcAttrs) . ' ';
}
$ret .= ($type == 'Method') ? 'method ' : 'function ';
if ($this->returnsReference()) {
$ret .= '&';
}
$ret .= $this->getName() . " ] {\n";
if ($this->getStartLine() > 0) {
$ret .= " @@ {$this->getFilename()} " .
"{$this->getStartLine()} - {$this->getEndLine()}\n";
}
if ($this->isClosure()) {
// TODO: Not enough info
}
$params = $this->getParameters();
if (count($params) > 0) {
$ret .= "\n - Parameters [" . count($params) . "] {\n ";
foreach ($params as $param) {
$ret .= ' '.str_replace("\n", "\n ", $param."\n");
}
$ret .= "}\n";
}
$ret .= "}\n";
return $ret;
}
}
/**
* ( excerpt from http://php.net/manual/en/class.reflectionfunction.php )
*
* The ReflectionFunction class reports information about a function.
*/
class ReflectionFunction extends ReflectionFunctionAbstract {
public string $name; // should be readonly (PHP compatibility)
private ?Closure $closure = null;
/**
* ( excerpt from http://php.net/manual/en/reflectionfunction.construct.php
* )
*
* Constructs a ReflectionFunction object.
*
* @name mixed The name of the function to reflect or a closure.
*
* @return mixed No value is returned.
*/
public function __construct($name_or_closure) {
if ($name_or_closure instanceof Closure) {
$this->closure = $name_or_closure;
$this->__initClosure($name_or_closure);
} else if (is_string($name_or_closure)){
if (!$this->__initName($name_or_closure)) {
throw new ReflectionException(
"Function $name_or_closure does not exist");
}
} else {
throw new ReflectionException(
sprintf('%s expects a string or a Closure, got %s',
__METHOD__, gettype($name_or_closure))
);
}
$this->name = $this->getName();
}
<<__Native>>
private function __initClosure(object $closure): bool;
<<__Native>>
private function __initName(string $name): bool;
/**
* (excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getname.php )
*
* Get the name of the function. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return string The name of the function.
*/
public function getName(): string {
if ($this->closure) {
// Format: Closure$scope;hash
$cls = get_class($this->closure);
$ns_end = strrpos($cls, '\\');
if ($ns_end !== false) {
$ns_start = strpos($cls, '$') + 1;
$ns = substr($cls, $ns_start, $ns_end - $ns_start);
return $ns.'\\{closure}';
}
return '{closure}';
}
return parent::getName();
}
public function getClosure() {
return $this->closure ?:
function(...$args) { return $this->invokeArgs($args); };
}
public function isClosure(): bool {
return (bool) $this->closure;
}
/**
* ( excerpt from http://php.net/manual/en/reflectionfunction.tostring.php )
*
* @return string A representation of this ReflectionFunction.
*/
public function __toString(): string {
return $this->__toStringHelper($this->isClosure() ? 'Closure' : 'Function');
}
/**
* ( excerpt from http://php.net/manual/en/reflectionfunction.export.php )
*
* Exports a Reflected function.
*
* @name mixed The reflection to export.
* @ret mixed Setting to TRUE will return the export, as opposed
* to emitting it. Setting to FALSE (the default) will
* do the opposite.
*
* @return mixed If the return parameter is set to TRUE, then the
* export is returned as a string, otherwise NULL is
* returned.
*/
public static function export($name, $ret=false) {
$obj = new self($name);
$str = (string) $obj;
if ($ret) {
return $str;
}
print $str;
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.getstaticvariables.php
* )
*
* Get the static variables. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed An array of static variables.
*/
public function getStaticVariables() {
$static_vars = parent::getStaticVariables();
return !$this->closure
? $static_vars
: array_merge( // XXX: which should win in key collision case?
$static_vars,
$this->getClosureUseVariables($this->closure),
);
}
<<__Native>>
private function getClosureUseVariables(object $closure): array;
/**
* ( excerpt from http://php.net/manual/en/reflectionfunction.invoke.php )
*
* Invokes a reflected function.
*
* @return mixed Returns the result of the invoked function call.
*/
public function invoke(...$args) {
if ($this->closure) {
return hphp_invoke_method($this->closure, get_class($this->closure),
'__invoke', $args);
}
return hphp_invoke($this->getName(), $args);
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunction.invokeargs.php )
*
* Invokes the function and pass its arguments as array.
*
* @args mixed The passed arguments to the function as an array,
* much like call_user_func_array() works.
*
* @return mixed Returns the result of the invoked function
*/
public function invokeArgs($args) {
if ($this->closure) {
return hphp_invoke_method($this->closure, get_class($this->closure),
'__invoke', array_values($args));
}
return hphp_invoke($this->getName(), array_values($args));
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunction.isdisabled.php )
*
* Checks if the function is disabled, via the disable_functions directive.
*
* @return bool TRUE if it's disable, otherwise FALSE
*/
public function isDisabled(): bool {
// FIXME: HHVM doesn't support the disable_functions directive.
return false;
}
<<__Native>>
private function getClosureScopeClassname(object $closure): ?string;
public function getClosureScopeClass(): ?ReflectionClass {
if ($this->closure &&
($cls = $this->getClosureScopeClassname($this->closure))) {
return new ReflectionClass($cls);
}
return null;
}
<<__Native>>
private function getClosureThisObject(object $closure): ?object;
/**
* Returns this pointer bound to closure.
*
* @return object|NULL Returns $this pointer. Returns NULL in case of
* an error.
*/
public function getClosureThis(): ?mixed {
if ($this->closure) {
return $this->getClosureThisObject($this->closure);
}
return null;
}
}
/**
* ( excerpt from http://php.net/manual/en/class.reflectionmethod.php )
*
* The ReflectionMethod class reports information about a method.
*/
class ReflectionMethod extends ReflectionFunctionAbstract {
public string $name; // should be readonly (PHP compatibility)
public string $class; // should be readonly (PHP compatibility)
private /*string*/ $originalClass;
private /*bool*/ $forcedAccessible = false;
<<__Native>>
private function __init(mixed $cls_or_obj, string $meth): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.construct.php )
*
* Constructs a new ReflectionMethod.
*
* Format 1:
*
* @cls mixed Classname or object (instance of the class) that
* contains the method.
* @name string Name of the method.
*
* Format 2:
*
* @class_and_method string Class name and method, separated by ::
*/
public function __construct(...) {
$args = func_get_args();
if (count($args) == 0 || count($args) > 2) {
throw new Exception(
'ReflectionMethod::__construct() takes either 1 or 2 arguments');
}
if (count($args) == 1) {
$arr = explode('::', $args[0], 3);
if (count($arr) !== 2) {
$name = $args[0];
throw new ReflectionException("$name is not a valid method name");
}
list($cls, $name) = $arr;
$classname = $cls;
} else {
$cls = $args[0];
$name = (string) $args[1];
$classname = is_object($cls) ? get_class($cls) : $cls;
$method = $args[1];
}
$this->originalClass = $classname;
if (!$this->__init($cls, (string) $name)) {
throw new ReflectionException(
"Method $classname::$name() does not exist");
}
$this->name = $this->getName();
$this->class = $this->getDeclaringClassname();
}
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.tostring.php )
*
* @return string A string representation of this ReflectionMethod.
*/
public function __toString(): string {
$preAttrs = [];
$decl_class = $this->getDeclaringClassname();
if ($this->originalClass !== $decl_class) {
$preAttrs[] = "inherits $decl_class";
} else if ($proto_cls = $this->getPrototypeClassname()) {
$preAttrs[] = interface_exists($proto_cls, false)
? 'implements '.$proto_cls
: 'overrides '.$proto_cls;
}
if ($this->isConstructor()) {
$preAttrs[] = 'ctor';
}
if ($this->isDestructor()) {
$preAttrs[] = 'dtor';
}
$funcAttrs = [];
if ($this->isAbstract()) {
$funcAttrs[] = 'abstract';
}
if ($this->isFinal()) {
$funcAttrs[] = 'final';
}
if ($this->isStatic()) {
$funcAttrs[] = 'static';
}
if ($this->isPrivate()) {
$funcAttrs[] = 'private';
} elseif ($this->isProtected()) {
$funcAttrs[] = 'protected';
} else {
$funcAttrs[] = 'public';
}
return $this->__toStringHelper('Method', $preAttrs, $funcAttrs);
}
public function __debuginfo() {
return array('name' => $this->name, 'class' => $this->class);
}
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.export.php )
*
* Exports a ReflectionMethod. Warning: This function is currently not
* documented; only its argument list is available.
*
* @cls mixed The class name.
* @name mixed The name of the method.
* @ret mixed Setting to TRUE will return the export, as opposed
* to emitting it. Setting to FALSE (the default) will
* do the opposite.
*
* @return ?string If the return parameter is set to TRUE, then the
* export is returned as a string, otherwise NULL is
* returned.
*/
public static function export(
string $cls,
string $name,
bool $ret = false,
): ?string {
$meth = new self($cls, $name);
$str = (string) $meth;
if ($ret) {
return $str;
}
print $str;
}
private function isAccessible(): bool {
return $this->forcedAccessible || $this->isPublic();
}
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.invoke.php )
*
* Invokes a reflected method.
*
* @obj mixed The object to invoke the method on. For static
* methods, pass null to this parameter.
*
* @return mixed Returns the method result.
*/
public function invoke($obj, ...$args): mixed {
$this->validateInvokeParameters($obj, $args);
if ($this->isStatic()) {
// Docs says to pass null, but Zend completely ignores the argument
$obj = null;
}
return hphp_invoke_method($obj, $this->originalClass,
$this->getName(), $args);
}
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.invokeargs.php
* )
*
* Invokes the reflected method and pass its arguments as array.
*
* @obj mixed The object to invoke the method on. In case of
* static methods, you can pass null to this parameter.
* @args mixed The parameters to be passed to the function, as an
* array.
*
* @return mixed Returns the method result.
*/
public function invokeArgs($obj, $args): mixed {
$this->validateInvokeParameters($obj, $args);
if ($this->isStatic()) {
$obj = null;
}
return hphp_invoke_method($obj, $this->originalClass, $this->getName(),
array_values($args));
}
private function validateInvokeParameters($obj, $args): mixed {
if (!$this->isAccessible()) {
throw new ReflectionException(
sprintf(
'Trying to invoke %s method %s::%s() from scope ReflectionMethod',
($this->isProtected() ? 'protected' : 'private'),
$this->getDeclaringClassname(), $this->getName(),
)
);
}
if (!$this->isStatic()) {
if (!$obj) {
$name = $this->originalClass.'::'.$this->getName();
throw new ReflectionException(
"Trying to invoke non static method $name() without an object",
);
}
}
}
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.isfinal.php )
*
* Checks if the method is final.
*
* @return bool TRUE if the method is final, otherwise FALSE
*/
<<__Native>>
public function isFinal(): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.isabstract.php
* )
*
* Checks if the method is abstract.
*
* @return bool TRUE if the method is abstract, otherwise FALSE
*/
<<__Native>>
public function isAbstract(): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.ispublic.php )
*
* Checks if the method is public.
*
* @return bool TRUE if the method is public, otherwise FALSE
*/
<<__Native>>
public function isPublic(): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.isprotected.php
* )
*
* Checks if the method is protected.
*
* @return bool TRUE if the method is protected, otherwise FALSE
*/
<<__Native>>
public function isProtected(): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.isprivate.php )
*
* Checks if the method is private. Warning: This function is currently
* not documented; only its argument list is available.
*
* @return bool TRUE if the method is private, otherwise FALSE
*/
<<__Native>>
public function isPrivate(): bool;
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.isstatic.php )
*
* Checks if the method is static.
*
* @return bool TRUE if the method is static, otherwise FALSE
*/
<<__Native>>
public function isStatic(): bool;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionmethod.isconstructor.php )
*
* Checks if the method is a constructor.
*
* @return bool TRUE if the method is a constructor, otherwise FALSE
*/
<<__Native>>
public function isConstructor(): bool;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionmethod.isdestructor.php )
*
* Checks if the method is a destructor.
*
* @return bool TRUE if the method is a destructor, otherwise FALSE
*/
public function isDestructor(): bool {
return $this->getName() == '__destruct';
}
/**
* ( excerpt from
* http://php.net/manual/en/reflectionmethod.getmodifiers.php )
*
* Returns a bitfield of the access modifiers for this method.
*
* @return int A numeric representation of the modifiers. The
* modifiers are listed below. The actual meanings of
* these modifiers are described in the predefined
* constants.
*/
<<__Native>>
public function getModifiers(): int;
/**
* ( excerpt from
* http://php.net/manual/en/reflectionmethod.getprototype.php )
*
* Returns the methods prototype.
*
* @return object A ReflectionMethod instance of the method prototype.
*/