- Timestamp:
- 2013-07-16T03:24:01Z (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mod_disassembler/sample.php
r1322 r1327 1 1 <?php 2 2 3 $a = new A(); 4 new B(); 5 a(); 6 $a = a(); 3 /* >= PHP 5.3 4 namespace ns; 5 // */ 6 7 abstract class ClassName 8 { 9 const CONST_VALUE = 'A constant value'; 10 11 /** doc */ 12 static public $static = array( 13 array('array'), 14 'str' 15 ); 16 /** doc */ 17 static public $public_static = array(2, 'str'); 18 /** doc */ 19 static private $private_static = array(2, 'str'); 20 /** doc */ 21 static protected $protected_static = array(2, 'str'); 22 /** doc */ 23 public $property = array( 24 array('array'), 25 'str' 26 ); 27 /** doc */ 28 public $public_property = array(2, 'str'); 29 /** doc */ 30 private $private_property = array(2, 'str'); 31 /** doc */ 32 protected $protected_property = array(2, 'str'); 33 34 /** doc */ 35 public function __construct($a, $b) 36 { 37 echo CONST_VALUE; 38 echo ClassName::CONST_VALUE; 39 empty(ClassName::$classProp); 40 isset(ClassName::$classProp); 41 unset(ClassName::$classProp); 42 ClassName::$classProp = 1; 43 echo ClassName::$classProp; 44 empty($obj->objProp); 45 isset($obj->objProp); 46 unset($obj->objProp); 47 $obj->objProp = 1; 48 echo $obj->objProp; 49 empty($this->thisProp); 50 isset($this->thisProp); 51 unset($this->thisProp); 52 $this->thisProp = 1; 53 echo $this->thisProp; 54 unset($array['index']->valueProp); 55 unset($obj->array['index']); 56 unset($this->array['index']); 57 empty($_GET['get']); 58 isset($_GET['get']); 59 unset($_GET['get']); 60 $_GET['get'] = 1; 61 echo $_GET['get']; 62 isset($GLOBALS['global']); 63 empty($GLOBALS['global']); 64 unset($GLOBALS['global']); 65 $GLOBALS['global'] = 1; 66 echo $GLOBALS['global']; 67 empty($array['index']); 68 isset($array['index']); 69 unset($array['index']); 70 $array['index'] = 1; 71 echo $array['index']; 72 empty($array['index']->indexProp); 73 isset($array['index']->indexProp); 74 unset($array['index']->indexProp); 75 $array['index']->indexProp = 1; 76 echo $array['index']->indexProp; 77 empty($GLOBALS['var']->indexProp); 78 isset($GLOBALS['var']->indexProp); 79 unset($GLOBALS['var']->indexProp); 80 $GLOBALS['var']->indexProp = 1; 81 echo $GLOBALS['var']->indexProp; 82 } 83 84 /** doc */ 85 abstract public function abastractMethod(); 86 87 /** doc */ 88 public function method($a = NULL, $b = NULL) 89 { 90 } 91 92 /** doc */ 93 public function publicMethod(ClassName $a = NULL, $b = 2) 94 { 95 } 96 97 /** doc */ 98 protected function protectedMethod(ClassName $a, $b = array( 99 array('array') 100 )) 101 { 102 $runtimeArray = array('1'); 103 $runtimeArray2 = array( 104 '1', 105 array() 106 ); 107 $runtimeArray3 = array( 108 'a' => '1', 109 2 => array() 110 ); 111 return 'protected'; 112 } 113 114 /** doc */ 115 private function privateMethod(ClassName $a, $b = NULL) 116 { 117 return 'private'; 118 } 119 } 120 121 interface IInterface 122 { 123 public function nothing(); 124 } 125 126 function f1($f) 127 { 128 echo __FUNCTION__; 129 echo $f; 130 } 131 132 final class Child extends ClassName implements IInterface 133 { 134 public function __construct() 135 { 136 parent::__construct(); 137 ClassName::__construct(); 138 echo __CLASS__; 139 echo __METHOD__; 140 echo __FUNCTION__; 141 throw new Exception(); 142 $this->methodCall(); 143 } 144 145 public function __destruct() 146 { 147 parent::__destruct(); 148 functionCall(); 149 } 150 151 static public function __callStatic($name, $args) 152 { 153 parent::__callStatic($name, $args); 154 } 155 156 public function __toString() 157 { 158 parent::__toString(); 159 } 160 161 public function __set($name, $value) 162 { 163 } 164 165 public function __get($name) 166 { 167 } 168 169 public function __isset($name) 170 { 171 } 172 173 public function __unset($name) 174 { 175 } 176 177 public function __sleep() 178 { 179 } 180 181 public function __wakeup() 182 { 183 } 184 185 public function __clone() 186 { 187 return array(); 188 } 189 } 190 191 if ($late) { 192 class LateBindingClass 193 { 194 public function __construct() 195 { 196 } 197 } 198 199 function lateBindingFunction($arg) 200 { 201 echo 'lateFunction'; 202 return new lateBindingFunction(); 203 } 204 } 205 206 echo "\r\n"; 207 echo "\r"; 208 echo "\n"; 209 echo str_replace(array('a' => 'a', 'b' => 'c'), 'b'); 210 $object = new ClassName(); 211 $object = new $className(); 212 $result = $object instanceof ClassName; 213 $cloned = clone $object; 214 $a = 1; 215 $a = $b + $c; 216 $a = $b + 1; 217 $a = 1 + $b; 218 $a = $b - $c; 219 $a = $b * $c; 220 $a = $b / $c; 221 $a = $b % $c; 222 $a = $b . $c; 223 $a = $b = $c; 224 $a = $b & $c; 225 $a = $b | $c; 226 $a = $b ^ $c; 227 $a = ~$b; 228 $a = -$b; 229 $a = +$b; 230 $a = $b >> $c; 231 $a = $b >> $c; 232 $a = $b == $c; 233 $a = $b === $c; 234 $a = $b != $c; 235 $a = $b < $c; 236 $a = $b <= $c; 237 $a = $b <= $c; 238 $a = $b++; 239 $a = ++$b; 240 $a = $obj->b++; 241 $a = ++$obj->b; 242 $a = $b--; 243 $a = --$b; 244 $a = $obj->b--; 245 $a = --$obj->b; 246 $a = !$b; 247 $a = $b === $c; 248 $a = $b !== $c; 249 $a = $b << 2; 250 $a = $b >> 3; 251 $a += $b; 252 $a -= $b; 253 $a *= $b; 254 $a /= $b; 255 $a <<= $b; 256 $a >>= $b; 257 $a &= $b; 258 $a |= $b; 259 $a .= $b; 260 $a %= $b; 261 $a ^= $b; 262 $a = 'a' . 'b'; 263 $a = 'a' . 'abc'; 264 @f1(); 265 print('1'); 266 // ref(&$a); 267 $a = $array['index']; 268 $a = $object->prop; 269 $a = $this->prop; 270 $array['index'] = 1; 271 $object->prop = 1; 272 $this->prop = 1; 273 $a = isset($b); 274 $a = empty($b); 275 unset($b); 276 $a = isset($array['index']); 277 $a = empty($array['index']); 278 unset($array['index']); 279 $a = isset($object->prop); 280 $a = empty($object->prop); 281 unset($object->prop); 282 $a = isset($this->prop); 283 $a = empty($this->prop); 284 unset($this->prop); 285 $a = isset(ClassName::$prop); 286 $a = empty(ClassName::$prop); 287 unset(ClassName::$prop); 288 $a = (int) $b; 289 $a = (double) $b; 290 $a = (string) $b; 291 $a = (array) $b; 292 $a = (object) $b; 293 $a = (bool) $b; 294 $a = (unset) $b; 295 $a = (array) $b; 296 $a = (object) $b; 297 // PHP6+ $a = (scalar) $b; 298 $a = ($b ? $c : $d); 299 $a = (f1() ? f2() : f3()); 300 ($a = $b) xor $c; 301 ($a = $b) and $c; 302 ($a = $b) or $c; 303 $a = $b && $c; 304 $a = $b || $c; 305 306 do { 307 try { 308 echo 'outer try 1'; 309 310 try { 311 echo 'inner try'; 312 } 313 catch (InnerException $e) { 314 echo $e; 315 } 316 317 echo 'outer try 2'; 318 } 319 catch (OuterException $e) { 320 echo $e; 321 } 322 } while (0); 323 324 if (if_()) { 325 echo 'if'; 326 327 if (innerIf_()) { 328 echo 'if innerIf'; 329 } 330 } 331 else if (elseif_()) { 332 echo 'else if'; 333 334 if (innerIf_()) { 335 echo 'if innerIf'; 336 } 337 } 338 else { 339 if (innerIf_()) { 340 echo 'if innerIf'; 341 } 342 343 echo 'else'; 344 } 345 346 while (false) { 347 echo 'while'; 348 } 349 350 do { 351 echo 'do/while'; 352 } while (false); 353 354 $i = 1; 355 356 for (; $i < 10; ++$i) { 357 echo $i; 358 break; 359 } 360 361 foreach ($array as $value) { 362 foreach ($value as $key => $value) { 363 echo $key . ' = ' . $value . "\n"; 364 break 2; 365 continue; 366 } 367 } 368 369 switch ($normalSwitch) { 370 case 'case1': 371 echo 'case1'; 372 373 switch ($nestedSwitch) { 374 case 1: 375 } 376 377 break; 378 379 case 'case2': 380 echo 'case2'; 381 break; 382 383 default: 384 switch ($nestedSwitch) { 385 case 1: 386 } 387 388 echo 'default'; 389 break; 390 } 391 392 switch ($switchWithoutDefault) { 393 case 'case1': 394 echo 'case1'; 395 break; 396 397 case 'case2': 398 echo 'case2'; 399 break; 400 } 401 402 switch ($switchWithMiddleDefault) { 403 case 'case1': 404 echo 'case1'; 405 break; 406 407 default: 408 echo 'default'; 409 break; 410 411 case 'case2': 412 echo 'case2'; 413 break; 414 } 415 416 switch ($switchWithInitialDefault) { 417 default: 418 echo 'default'; 419 break; 420 421 case 'case1': 422 echo 'case1'; 423 break; 424 425 case 'case2': 426 echo 'case2'; 427 break; 428 } 429 430 switch (emptySwitch()) { 431 } 432 433 switch (emptySwitch()) { 434 default: 435 } 436 437 declare (ticks=1) { 438 echo 1; 439 } 440 441 while (1) { 442 declare (ticks=1) { 443 echo 2; 444 } 445 } 446 447 require 'require.php'; 448 require_once 'require_once.php'; 449 include 'include.php'; 450 include_once 'include_once.php'; 451 echo __FILE__; 452 echo __LINE__; 453 454 /* 455 echo 'PHP 5.3+ code testing'; 456 const CONST_VALUE = 1; 457 echo $this::CONST_VALUE; 458 echo $a::CONST_VALUE; 459 echo CONST_VALUE; 460 $this::__construct(); 461 $obj::__construct(); 462 $a = $b ?: $d; 463 $a = ($b ?: $d) + $c; 464 $a = f1() ?: f2(); 465 $a = C::f1() ?: C::f2(); 466 $a = ($b ? $c : $d); 467 $a = ($b ? $c : $d) + $c; 468 $a = (f1() ? f3() : f2()); 469 470 if ($b ?: $d) { 471 echo 'if ($b ?: $d)'; 472 } 473 474 if (($b ?: $d) + $c) { 475 echo 'if (($b ?: $d) + $c)'; 476 } 477 478 if (f1() ?: f2()) { 479 echo 'if (f1() ?: f2())'; 480 } 481 482 echo 'goto a'; 483 goto a; 484 485 $i = 1; 486 487 for (; $i <= 2; ++$i) { 488 goto a; 489 } 490 491 a: 492 echo 'label a'; 493 echo preg_replace_callback('~-([a-z])~', function($match) { 494 return strtoupper($match[1]); 495 }, 'hello-world'); 496 $greet = function($name) { 497 printf("Hello %s\r\n", $name); 498 }; 499 $greet('World'); 500 $greet('PHP'); 501 $total = 0; 502 $tax = 1; 503 $callback = function($quantity, $product) use($tax, &$total) { 504 $tax = 'tax'; 505 static $static1 = array(1); 506 static $static2; 507 $tax = 'tax'; 508 $tax = --$tax; 509 $pricePerItem = constant('PRICE_' . strtoupper($product)); 510 $total += $pricePerItem * $quantity * ($tax + 1); 511 }; 512 // */ 513 exit(); 7 514 8 515 ?>
Note: See TracChangeset
for help on using the changeset viewer.