|
1
|
|
|
<?php |
|
2
|
|
|
require_once('NamedArgs.php'); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
function codeWithoutRef(NamedArgs $mandatory) |
|
7
|
|
|
{ |
|
8
|
|
|
$required=['first','fourth'];//specify required parameters here |
|
9
|
|
|
$default=['first'=>0,'second'=>1,'third'=>2,'fourth'=>9,'fifth'=>7];//define all parameters required and optional with their default values here |
|
10
|
|
|
extract($mandatory->getParams($required, $default)); |
|
11
|
|
|
unset($mandatory); |
|
12
|
|
|
return $first+$second+$third+$fourth+$fifth; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
function codeWithRef(NamedArgs $mandatory) |
|
17
|
|
|
{ |
|
18
|
|
|
$required=['first']; |
|
19
|
|
|
$default=['first'=>0,'second'=>1,'third'=>2]; |
|
20
|
|
|
extract($mandatory->getParams($required, $default), EXTR_OVERWRITE|EXTR_REFS); |
|
21
|
|
|
unset($mandatory); |
|
22
|
|
|
$first=$first+$second+$third; |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
function test(&$tada, &$tada2, &$test=6) |
|
27
|
|
|
{ |
|
28
|
|
|
$tada=1; |
|
29
|
|
|
$tada2=2; |
|
30
|
|
|
return $tada+$tada2+$test; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
echo "<pre>"; |
|
35
|
|
|
var_dump(codeWithoutRef(Args(['fourth'=>9,'first'=>3,'third'=>79]))); |
|
36
|
|
|
var_dump(codeWithoutRef(Args([1,2,3,0]))); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$first=3; |
|
40
|
|
|
codeWithRef(Args(['third'=>79,'first'=>&$first])); |
|
41
|
|
|
var_dump($first); |
|
42
|
|
|
$first2=3; |
|
43
|
|
|
codeWithRef(Args([&$first2,79])); |
|
44
|
|
|
var_dump($first2); |
|
45
|
|
|
|
|
46
|
|
|
$tada=$tada2=null; |
|
47
|
|
|
var_dump(NamedArgs::test(args(['tada'=>&$tada,'tada2'=>&$tada2])), $tada, $tada2); |
|
48
|
|
|
|
|
49
|
|
|
$tada=$tada2=null; |
|
50
|
|
|
var_dump(NamedArgs::test(args([&$tada,&$tada2])), $tada, $tada2); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
NamedArgs::preg_match_all(args(['subpatterns'=>&$matches,'pattern'=>'#a|o|i|u|e#','subject'=>'gris|gros|gras|grue'])); |
|
54
|
|
|
|
|
55
|
|
|
var_dump($matches); |
|
56
|
|
|
var_dump($x=NamedArgs::strtoupper(args(['str'=>'gris|gros|gras|grue'])), NamedArgs::strtolower(args(['str'=>$x])));//just for funny example. |
|
57
|
|
|
NamedArgs::preg_match(['subpatterns'=>&$match,'pattern'=>'#a|o|i|u|e#','subject'=>'gris|gros|gras|grue']); |
|
58
|
|
|
var_dump($match); |
|
59
|
|
|
|
|
60
|
|
|
highlight_string(' |
|
61
|
|
|
<?php |
|
62
|
|
|
var_dump(codeWithoutRef(Args([\'third\'=>79])));//generate error here for example |
|
63
|
|
|
?> |
|
64
|
|
|
'); |
|
65
|
|
|
var_dump(codeWithoutRef(Args(['third'=>79]))); |
|
66
|
|
|
|
|
67
|
|
|
echo "</pre>"; |
|
68
|
|
|
|