PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/slow/lang/fsc.php

https://gitlab.com/Blueprint-Marketing/hhvm
PHP | 481 lines | 445 code | 11 blank | 25 comment | 0 complexity | c383fc03a8957612e66d51e75d85d064 MD5 | raw file
  1. <?php
  2. error_reporting(-1);
  3. class A {
  4. public function foo() {
  5. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  6. (isset($this) ? get_class($this) : '') . "\n";
  7. }
  8. public static function bar() {
  9. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  10. (isset($this) ? get_class($this) : '') . "\n";
  11. }
  12. }
  13. class B extends A {
  14. public function foo() {
  15. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  16. (isset($this) ? get_class($this) : '') . "\n";
  17. }
  18. public static function bar() {
  19. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  20. (isset($this) ? get_class($this) : '') . "\n";
  21. }
  22. public function doFoo() {
  23. $this->foo(); // B B B
  24. B::foo(); // B B B
  25. C::foo(); // C C (Zend outputs: C B B) (Rule 1)
  26. D::foo(); // D D (Zend outputs: D B B) (Rule 1)
  27. F::foo(); // F F (Zend outputs: F B B) (Rule 1)
  28. G::foo(); // G G (Zend outputs: G B B) (Rule 1)
  29. H::foo(); // H H (Zend outputs: H B B) (Rule 1)
  30. parent::foo(); // A B B
  31. self::foo(); // B B B
  32. static::foo(); // B B B
  33. echo "****************\n";
  34. }
  35. public function doBar() {
  36. $this->bar(); // B B
  37. B::bar(); // B B
  38. C::bar(); // C C
  39. D::bar(); // D D
  40. F::bar(); // F F
  41. G::bar(); // G G
  42. H::bar(); // H H
  43. parent::bar(); // A B
  44. self::bar(); // B B
  45. static::bar(); // B B
  46. echo "****************\n";
  47. }
  48. }
  49. class C extends B {
  50. public function foo() {
  51. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  52. (isset($this) ? get_class($this) : '') . "\n";
  53. }
  54. public static function bar() {
  55. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  56. (isset($this) ? get_class($this) : '') . "\n";
  57. }
  58. /**
  59. * Zend's implementation of call_user_func() and forward_static_call() has
  60. * a few corner cases where its behavior is strictly incorrect. HipHop will
  61. * match Zend's behavior except for cases that violate one of the following
  62. * invariants:
  63. * 1) If the current instance ($this) is non-null, the class of the current
  64. * instance must be the same or a descendent of the class enclosing the
  65. * current method. The PHP group is in the process of depracating this
  66. * behavior. HipHop explicitly lists this in the inconsistencies doc.
  67. * 2) If the current instance ($this) is non-null, the class of the current
  68. * instance must be the same as the current late bound class (aka the
  69. * "called class"). This invariant is stated explicitly in PHP5's
  70. * documentation: "In non-static contexts, the called class will be the
  71. * class of the object instance."
  72. * 3) Normal style calls and call_user_func style calls should produce
  73. * consistent results aside from any exceptions mentioned in PHP5's
  74. * documentation. Therefore, "B::foo()" and "call_user_func('B::foo')"
  75. * and "call_user_func(array('B', 'foo'))" should all produce consistent
  76. * results.
  77. * 4) call_user_func() and forward_static_call() must never forward the
  78. * caller's late bound class to the callee if the late bound class is
  79. * not the same or a descendent of the class enclosing the method.
  80. * Zend's implementation of forward_static_call contains a check for
  81. * this, implying intent to uphold this invariant.
  82. */
  83. public function testFoo1() {
  84. echo "############# testFoo1 ##############\n";
  85. B::foo(); // B D D
  86. C::foo(); // C D D
  87. D::foo(); // D D D
  88. F::foo(); // F F (Zend: F D D) (Rule 1)
  89. G::foo(); // G G (Zend: G D D) (Rule 1)
  90. H::foo(); // H H (Zend: H D D) (Rule 1)
  91. parent::foo(); // B D D
  92. self::foo(); // C D D
  93. static::foo(); // D D D
  94. echo "****************\n";
  95. forward_static_call(array('B','foo')); // B D D
  96. forward_static_call(array('C','foo')); // C D D
  97. forward_static_call(array('D','foo')); // D D D
  98. forward_static_call(array('F','foo')); // F F
  99. forward_static_call(array('G','foo')); // G G
  100. forward_static_call(array('H','foo')); // H H
  101. forward_static_call(array('parent','foo')); // B D D
  102. forward_static_call(array('self','foo')); // C D D
  103. forward_static_call(array('static','foo')); // D D D
  104. echo "****************\n";
  105. forward_static_call('B::foo'); // B D D
  106. forward_static_call('C::foo'); // C D D
  107. forward_static_call('D::foo'); // D D D
  108. forward_static_call('F::foo'); // F F
  109. forward_static_call('G::foo'); // G G
  110. forward_static_call('H::foo'); // H H
  111. forward_static_call('parent::foo'); // B D D
  112. forward_static_call('self::foo'); // C D D
  113. forward_static_call('static::foo'); // D D D
  114. echo "****************\n";
  115. forward_static_call(array('B','B::foo')); // B D D
  116. forward_static_call(array('B','C::foo')); // warning
  117. forward_static_call(array('B','D::foo')); // warning
  118. forward_static_call(array('B','F::foo')); // warning
  119. forward_static_call(array('B','G::foo')); // warning
  120. forward_static_call(array('B','H::foo')); // warning
  121. forward_static_call(array('B','parent::foo')); // A D D
  122. forward_static_call(array('B','self::foo')); // B D D
  123. forward_static_call(array('B','static::foo')); // warning
  124. echo "****************\n";
  125. forward_static_call(array('G','B::foo')); // warning
  126. forward_static_call(array('G','C::foo')); // warning
  127. forward_static_call(array('G','D::foo')); // warning
  128. forward_static_call(array('G','F::foo')); // F F
  129. forward_static_call(array('G','G::foo')); // G G
  130. forward_static_call(array('G','H::foo')); // warning
  131. forward_static_call(array('G','parent::foo')); // F F (Zend: F D D) (Rule 1)
  132. forward_static_call(array('G','self::foo')); // G G (Zend: G D D) (Rule 1)
  133. forward_static_call(array('G','static::foo')); // warning
  134. echo "****************\n";
  135. $b = new B;
  136. forward_static_call(array($b,'foo')); // B B B (Zend: B D B) (Rule 2)
  137. forward_static_call(array($b,'B::foo')); // B B B (Zend: B D B) (Rule 2)
  138. forward_static_call(array($b,'C::foo')); // warning
  139. forward_static_call(array($b,'D::foo')); // warning
  140. forward_static_call(array($b,'F::foo')); // warning
  141. forward_static_call(array($b,'G::foo')); // warning
  142. forward_static_call(array($b,'H::foo')); // warning
  143. forward_static_call(array($b,'parent::foo')); // A B B (Zend: A D B) (Rule2)
  144. forward_static_call(array($b,'self::foo')); // B B B (Zend: B D B) (Rule2)
  145. forward_static_call(array($b,'static::foo')); // warning
  146. echo "****************\n";
  147. $g = new G;
  148. forward_static_call(array($g,'foo')); // G G G
  149. forward_static_call(array($g,'B::foo')); // warning
  150. forward_static_call(array($g,'C::foo')); // warning
  151. forward_static_call(array($g,'D::foo')); // warning
  152. forward_static_call(array($g,'F::foo')); // F G G
  153. forward_static_call(array($g,'G::foo')); // G G G
  154. forward_static_call(array($g,'H::foo')); // warning
  155. forward_static_call(array($g,'parent::foo')); // F G G
  156. forward_static_call(array($g,'self::foo')); // G G G
  157. forward_static_call(array($g,'static::foo')); // warning
  158. echo "****************\n";
  159. }
  160. public static function testFoo2() {
  161. echo "############# testFoo2 ##############\n";
  162. B::foo(); // B B
  163. C::foo(); // C C
  164. D::foo(); // D D
  165. F::foo(); // F F
  166. G::foo(); // G G
  167. H::foo(); // H H
  168. parent::foo(); // B D
  169. self::foo(); // C D
  170. static::foo(); // D D
  171. echo "****************\n";
  172. forward_static_call(array('B','foo')); // B D
  173. forward_static_call(array('C','foo')); // C D
  174. forward_static_call(array('D','foo')); // D D
  175. forward_static_call(array('F','foo')); // F F
  176. forward_static_call(array('G','foo')); // G G
  177. forward_static_call(array('H','foo')); // H H
  178. forward_static_call(array('parent','foo')); // B D
  179. forward_static_call(array('self','foo')); // C D
  180. forward_static_call(array('static','foo')); // D D
  181. echo "****************\n";
  182. forward_static_call('B::foo'); // B D
  183. forward_static_call('C::foo'); // C D
  184. forward_static_call('D::foo'); // D D
  185. forward_static_call('F::foo'); // F F
  186. forward_static_call('G::foo'); // G G
  187. forward_static_call('H::foo'); // H H
  188. forward_static_call('parent::foo'); // B D
  189. forward_static_call('self::foo'); // C D
  190. forward_static_call('static::foo'); // D D
  191. echo "****************\n";
  192. forward_static_call(array('B','B::foo')); // B D
  193. forward_static_call(array('B','C::foo')); // warning
  194. forward_static_call(array('B','D::foo')); // warning
  195. forward_static_call(array('B','F::foo')); // warning
  196. forward_static_call(array('B','G::foo')); // warning
  197. forward_static_call(array('B','H::foo')); // warning
  198. forward_static_call(array('B','parent::foo')); // A D
  199. forward_static_call(array('B','self::foo')); // B D
  200. forward_static_call(array('B','static::foo')); // warning
  201. echo "****************\n";
  202. forward_static_call(array('G','B::foo')); // warning
  203. forward_static_call(array('G','C::foo')); // warning
  204. forward_static_call(array('G','D::foo')); // warning
  205. forward_static_call(array('G','F::foo')); // F F
  206. forward_static_call(array('G','G::foo')); // G G
  207. forward_static_call(array('G','H::foo')); // warning
  208. forward_static_call(array('G','parent::foo')); // F F (Zend: F D) (Rule 4)
  209. forward_static_call(array('G','self::foo')); // G G (Zend: G D) (Rule 4)
  210. forward_static_call(array('G','static::foo'));
  211. echo "****************\n";
  212. $b = new B;
  213. forward_static_call(array($b,'foo')); // B B B
  214. forward_static_call(array($b,'B::foo')); // B B B
  215. forward_static_call(array($b,'C::foo')); // warning
  216. forward_static_call(array($b,'D::foo')); // warning
  217. forward_static_call(array($b,'F::foo')); // warning
  218. forward_static_call(array($b,'G::foo')); // warning
  219. forward_static_call(array($b,'H::foo')); // warning
  220. forward_static_call(array($b,'parent::foo')); // A B B
  221. forward_static_call(array($b,'self::foo')); // B B B
  222. forward_static_call(array($b,'static::foo')); // warning
  223. echo "****************\n";
  224. $g = new G;
  225. forward_static_call(array($g,'foo')); // G G G
  226. forward_static_call(array($g,'B::foo')); // warning
  227. forward_static_call(array($g,'C::foo')); // warning
  228. forward_static_call(array($g,'D::foo')); // warning
  229. forward_static_call(array($g,'F::foo')); // F G G
  230. forward_static_call(array($g,'G::foo')); // G G G
  231. forward_static_call(array($g,'H::foo')); // warning
  232. forward_static_call(array($g,'parent::foo')); // F G G
  233. forward_static_call(array($g,'self::foo')); // G G G
  234. forward_static_call(array($g,'static::foo')); // warning
  235. echo "****************\n";
  236. }
  237. public function testBar1() {
  238. echo "############# testBar1 ##############\n";
  239. B::bar(); // B B
  240. C::bar(); // C C
  241. D::bar(); // D D
  242. F::bar(); // F F
  243. G::bar(); // G G
  244. H::bar(); // H H
  245. parent::bar(); // B D
  246. self::bar(); // C D
  247. static::bar(); // D D
  248. echo "****************\n";
  249. forward_static_call(array('B','bar')); // B D
  250. forward_static_call(array('C','bar')); // C D
  251. forward_static_call(array('D','bar')); // D D
  252. forward_static_call(array('F','bar')); // F F
  253. forward_static_call(array('G','bar')); // G G
  254. forward_static_call(array('H','bar')); // H H
  255. forward_static_call(array('parent','bar')); // B D
  256. forward_static_call(array('self','bar')); // C D
  257. forward_static_call(array('static','bar')); // D D
  258. echo "****************\n";
  259. forward_static_call('B::bar'); // B D
  260. forward_static_call('C::bar'); // C D
  261. forward_static_call('D::bar'); // D D
  262. forward_static_call('F::bar'); // F F
  263. forward_static_call('G::bar'); // G G
  264. forward_static_call('H::bar'); // H H
  265. forward_static_call('parent::bar'); // B D
  266. forward_static_call('self::bar'); // C D
  267. forward_static_call('static::bar'); // D D
  268. echo "****************\n";
  269. forward_static_call(array('B','B::bar')); // B D
  270. forward_static_call(array('B','C::bar')); // warning
  271. forward_static_call(array('B','D::bar')); // warning
  272. forward_static_call(array('B','F::bar')); // warning
  273. forward_static_call(array('B','G::bar')); // warning
  274. forward_static_call(array('B','H::bar')); // warning
  275. forward_static_call(array('B','parent::bar')); // A D
  276. forward_static_call(array('B','self::bar')); // B D
  277. forward_static_call(array('B','static::bar')); // warning
  278. echo "****************\n";
  279. forward_static_call(array('G','B::bar'));
  280. forward_static_call(array('G','C::bar'));
  281. forward_static_call(array('G','D::bar'));
  282. forward_static_call(array('G','F::bar')); // F F
  283. forward_static_call(array('G','G::bar')); // G G
  284. forward_static_call(array('G','H::bar'));
  285. forward_static_call(array('G','parent::bar')); // F F (Zend: F D) (Rule 4)
  286. forward_static_call(array('G','self::bar')); // G G (Zend: G D) (Rule 4)
  287. forward_static_call(array('G','static::bar'));
  288. echo "****************\n";
  289. $b = new B;
  290. forward_static_call(array($b,'bar')); // B D
  291. forward_static_call(array($b,'B::bar')); // B D
  292. forward_static_call(array($b,'C::bar')); // warning
  293. forward_static_call(array($b,'D::bar')); // warning
  294. forward_static_call(array($b,'F::bar')); // warning
  295. forward_static_call(array($b,'G::bar')); // warning
  296. forward_static_call(array($b,'H::bar')); // warning
  297. forward_static_call(array($b,'parent::bar')); // A D
  298. forward_static_call(array($b,'self::bar')); // B D
  299. forward_static_call(array($b,'static::bar')); // warning
  300. echo "****************\n";
  301. $g = new G;
  302. forward_static_call(array($g,'bar')); // G G
  303. forward_static_call(array($g,'B::bar')); // warning
  304. forward_static_call(array($g,'C::bar')); // warning
  305. forward_static_call(array($g,'D::bar')); // warning
  306. forward_static_call(array($g,'F::bar')); // F G
  307. forward_static_call(array($g,'G::bar')); // G G
  308. forward_static_call(array($g,'H::bar')); // warning
  309. forward_static_call(array($g,'parent::bar')); // F G
  310. forward_static_call(array($g,'self::bar')); // G G
  311. forward_static_call(array($g,'static::bar')); // warning
  312. echo "****************\n";
  313. }
  314. public static function testBar2() {
  315. echo "############# testBar2 ##############\n";
  316. B::bar(); // B B
  317. C::bar(); // C C
  318. D::bar(); // D D
  319. F::bar(); // F F
  320. G::bar(); // G G
  321. H::bar(); // H H
  322. parent::bar(); // B D
  323. self::bar(); // C D
  324. static::bar(); // D D
  325. echo "****************\n";
  326. forward_static_call(array('B','bar')); // B D
  327. forward_static_call(array('C','bar')); // C D
  328. forward_static_call(array('D','bar')); // D D
  329. forward_static_call(array('F','bar')); // F F
  330. forward_static_call(array('G','bar')); // G G
  331. forward_static_call(array('H','bar')); // H H
  332. forward_static_call(array('parent','bar')); // B D
  333. forward_static_call(array('self','bar')); // C D
  334. forward_static_call(array('static','bar')); // D D
  335. echo "****************\n";
  336. forward_static_call('B::bar'); // B D
  337. forward_static_call('C::bar'); // C D
  338. forward_static_call('D::bar'); // D D
  339. forward_static_call('F::bar'); // F F
  340. forward_static_call('G::bar'); // G G
  341. forward_static_call('H::bar'); // H H
  342. forward_static_call('parent::bar'); // B D
  343. forward_static_call('self::bar'); // C D
  344. forward_static_call('static::bar'); // D D
  345. echo "****************\n";
  346. forward_static_call(array('B','B::bar')); // B D
  347. forward_static_call(array('B','C::bar')); // warning
  348. forward_static_call(array('B','D::bar')); // warning
  349. forward_static_call(array('B','F::bar')); // warning
  350. forward_static_call(array('B','G::bar')); // warning
  351. forward_static_call(array('B','H::bar')); // warning
  352. forward_static_call(array('B','parent::bar')); // A D
  353. forward_static_call(array('B','self::bar')); // B D
  354. forward_static_call(array('B','static::bar')); // warning
  355. echo "****************\n";
  356. forward_static_call(array('G','B::bar'));
  357. forward_static_call(array('G','C::bar'));
  358. forward_static_call(array('G','D::bar'));
  359. forward_static_call(array('G','F::bar')); // F F
  360. forward_static_call(array('G','G::bar')); // G G
  361. forward_static_call(array('G','H::bar'));
  362. forward_static_call(array('G','parent::bar')); // F F (Zend: F D) (Rule 4)
  363. forward_static_call(array('G','self::bar')); // G G (Zend: G D) (Rule 4)
  364. forward_static_call(array('G','static::bar'));
  365. echo "****************\n";
  366. $b = new B;
  367. forward_static_call(array($b,'bar')); // B D
  368. forward_static_call(array($b,'B::bar')); // B D
  369. forward_static_call(array($b,'C::bar'));
  370. forward_static_call(array($b,'D::bar'));
  371. forward_static_call(array($b,'F::bar'));
  372. forward_static_call(array($b,'G::bar'));
  373. forward_static_call(array($b,'H::bar'));
  374. forward_static_call(array($b,'parent::bar')); // A D
  375. forward_static_call(array($b,'self::bar')); // B D
  376. forward_static_call(array($b,'static::bar'));
  377. echo "****************\n";
  378. $g = new G;
  379. forward_static_call(array($g,'bar')); // G G
  380. forward_static_call(array($g,'B::bar')); // warning
  381. forward_static_call(array($g,'C::bar')); // warning
  382. forward_static_call(array($g,'D::bar')); // warning
  383. forward_static_call(array($g,'F::bar')); // F G
  384. forward_static_call(array($g,'G::bar')); // G G
  385. forward_static_call(array($g,'H::bar')); // warning
  386. forward_static_call(array($g,'parent::bar')); // F G
  387. forward_static_call(array($g,'self::bar')); // G G
  388. forward_static_call(array($g,'static::bar')); // warning
  389. echo "****************\n";
  390. }
  391. }
  392. class D extends C {
  393. public function foo() {
  394. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  395. (isset($this) ? get_class($this) : '') . "\n";
  396. }
  397. public static function bar() {
  398. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  399. (isset($this) ? get_class($this) : '') . "\n";
  400. }
  401. }
  402. class F {
  403. public function foo() {
  404. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  405. (isset($this) ? get_class($this) : '') . "\n";
  406. }
  407. public static function bar() {
  408. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  409. (isset($this) ? get_class($this) : '') . "\n";
  410. }
  411. }
  412. class G extends F {
  413. public function foo() {
  414. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  415. (isset($this) ? get_class($this) : '') . "\n";
  416. }
  417. public static function bar() {
  418. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  419. (isset($this) ? get_class($this) : '') . "\n";
  420. }
  421. public function doFoo() {
  422. $this->foo(); // G G G
  423. B::foo(); // B B (Zend: B G G) (Rule 1)
  424. C::foo(); // C C (Zend: C G G) (Rule 1)
  425. D::foo(); // D D (Zend: D G G) (Rule 1)
  426. F::foo(); // F G G
  427. G::foo(); // G G G
  428. H::foo(); // H H (Zend: H G G) (Rule 1)
  429. parent::foo(); // F G G
  430. self::foo(); // G G G
  431. static::foo(); // G G G
  432. echo "****************\n";
  433. }
  434. public function doBar() {
  435. $this->bar(); // G G
  436. B::bar(); // B B
  437. C::bar(); // C C
  438. D::bar(); // D D
  439. F::bar(); // F F
  440. G::bar(); // G G
  441. H::bar(); // H H
  442. parent::bar(); // F G
  443. self::bar(); // G G
  444. static::bar(); // G G
  445. echo "****************\n";
  446. }
  447. }
  448. class H extends G {
  449. public function foo() {
  450. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  451. (isset($this) ? get_class($this) : '') . "\n";
  452. }
  453. public static function bar() {
  454. echo __CLASS__ . ' ' . get_called_class() . ' ' .
  455. (isset($this) ? get_class($this) : '') . "\n";
  456. }
  457. }
  458. $d = new D;
  459. $d->testFoo1();
  460. D::testFoo2();
  461. $d->testBar1();
  462. D::testBar2();
  463. $b = new B;
  464. $g = new G;
  465. echo "############# doFoo ##############\n";
  466. $b->doFoo();
  467. $g->doFoo();
  468. echo "############# doBar ##############\n";
  469. $b->doBar();
  470. $g->doBar();