1<?php 2 3/* This is sample code just to exercise the parse a little, and cover most of 4 * what it handles but other tests don't cover so we exercise most code paths. 5 */ 6 7function func1($n, $c) { 8 $str = ''; 9 for ($i = 0; $i < $n; $i++) { 10 $str .= $c; 11 } 12 return strlen($str) > 0 ? $str : null; 13} 14 15function scisors($width) { 16 $left = (int) (($width - 4) / 2); 17 return func1($left, '-') . ' >8 ' . func1($width - 4 - $left, '-'); 18} 19 20abstract class Acls1 { 21 public function __construct ($args = null) { 22 /* if args are not given, set up defaults */ 23 if ($args == null) 24 $args = array('name' => 'doe', 'give-name' => 'john'); 25 26 // make sure arguments are valid 27 foreach ($args as $k => $v) 28 assert(in_array($k, array('name', 'given-name', 'surname'))); 29 30 $this->present($args); 31 } 32 33 protected abstract function present($args); 34} 35 36class Cls1 extends Acls1 { 37 protected function present($args) { 38 foreach ($args as $k => $v) { 39 if ($k == 'name') 40 print "My name is $v\n"; 41 elseif ($k === 'surname') 42 print "Call me $v\n"; 43 } 44 } 45} 46 47function func2($a, $b = ((4 + 1) * 2 - 4 / 2)) { 48 while ($a > $b) 49 $a /= 2; 50 return $a; 51} 52 53/* this one is *really* silly */ 54function func3( 55 $a = (0 ? 1 : 0) * 2, 56 $b = [1, 2, 3], 57 $c = "Hello", 58 $d = array('foo' => 42, 'bar' => 43) 59):string { 60 return $c.$d['foo'].$b[1].$a; 61} 62 63define('WIDTH', 36 * ((4 + 2) / 3)); 64 65# --------------------------------------------------------------------------- # 66echo scisors(WIDTH), "\n"; 67$cls1 = new Cls1(); 68echo scisors(72), "\n"; 69 70echo func2(6, 5), "\n"; 71 72$name = <<<NAME 73hello 74NAME; 75$$name = 'world'; 76echo "hello $hello\n"; 77 78echo func3(), "\n"; 79 80$obj = new class(array(1, 2, 3), (1 + 2) * 3) { 81 function __construct($a, $b) { 82 echo $b,"\n"; 83 } 84}; 85