PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/general_functions/is_object.php

http://github.com/facebook/hiphop-php
PHP | 151 lines | 108 code | 22 blank | 21 comment | 0 complexity | a77280a08984c0ea70dbd639331bc820 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype: bool is_object ( mixed $var );
  3. * Description: Finds whether the given variable is an object
  4. */
  5. echo "*** Testing is_object() with valid objects ***\n";
  6. // class with no members
  7. class foo
  8. {
  9. // no members
  10. }
  11. // abstract class
  12. abstract class abstractClass
  13. {
  14. abstract protected function getClassName();
  15. public function printClassName () {
  16. echo $this->getClassName() . "\n";
  17. }
  18. }
  19. // implement abstract class
  20. class concreteClass extends abstractClass
  21. {
  22. protected function getClassName() {
  23. return "concreteClass";
  24. }
  25. }
  26. // interface class
  27. interface IValue
  28. {
  29. public function setVal ($name, $val);
  30. public function dumpVal ();
  31. }
  32. // implement the interface
  33. class Value implements IValue
  34. {
  35. private $vars = array ();
  36. public function setVal ( $name, $val ) {
  37. $this->vars[$name] = $val;
  38. }
  39. public function dumpVal () {
  40. var_dump ( $vars );
  41. }
  42. }
  43. // a gereral class
  44. class myClass
  45. {
  46. var $foo_object;
  47. public $public_var;
  48. public $public_var1;
  49. private $private_var;
  50. protected $protected_var;
  51. function myClass ( ) {
  52. $this->foo_object = new foo();
  53. $this->public_var = 10;
  54. $this->public_var1 = new foo();
  55. $this->private_var = new foo();
  56. $this->proected_var = new foo();
  57. }
  58. }
  59. // create a object of each class defined above
  60. $myClass_object = new myClass();
  61. $foo_object = new foo();
  62. $Value_object = new Value();
  63. $concreteClass_object = new concreteClass();
  64. $valid_objects = array(
  65. new stdclass,
  66. new foo,
  67. new concreteClass,
  68. new Value,
  69. new myClass,
  70. $myClass_object,
  71. $myClass_object->foo_object,
  72. $myClass_object->public_var1,
  73. $foo_object,
  74. $Value_object,
  75. $concreteClass_object
  76. );
  77. /* loop to check that is_object() recognizes different
  78. objects, expected output: bool(true) */
  79. $loop_counter = 1;
  80. foreach ($valid_objects as $object ) {
  81. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  82. var_dump( is_object($object) );
  83. }
  84. echo "\n*** Testing is_object() on non object types ***\n";
  85. // get a resource type variable
  86. $fp = fopen (__FILE__, "r");
  87. $dfp = opendir ( dirname(__FILE__) );
  88. // unset object
  89. $unset_object = new foo();
  90. unset ($unset_object);
  91. // other types in a array
  92. $not_objects = array (
  93. 0,
  94. -1,
  95. 0.1,
  96. -10.0000000000000000005,
  97. 10.5e+5,
  98. 0xFF,
  99. 0123,
  100. $fp, // resource
  101. $dfp,
  102. array(),
  103. array("string"),
  104. "0",
  105. "1",
  106. "",
  107. true,
  108. NULL,
  109. null,
  110. @$unset_object, // unset object
  111. @$undefined_var, // undefined variable
  112. );
  113. /* loop through the $not_objects to see working of
  114. is_object() on non object types, expected output: bool(false) */
  115. $loop_counter = 1;
  116. foreach ($not_objects as $type ) {
  117. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  118. var_dump( is_object($type) );
  119. }
  120. echo "\n*** Testing error conditions ***\n";
  121. //Zero argument
  122. var_dump( is_object() );
  123. //arguments more than expected
  124. var_dump( is_object($myClass_object, $myClass_object) );
  125. echo "Done\n";
  126. // close the resources used
  127. fclose($fp);
  128. closedir($dfp);
  129. ?>