HOME   SITEMAP   CONTACT   NEWS   BLOG
Search


Developer PHP Syntax Exam


Do you know what empty(false) evaluates to? or empty('0')? How about ('-1' == true)? Well see yourself :-)

This test was created based on php 4.0.5, and is updated for php 4.2.2. All this has been proofed on Win2k using PHP 4.2.2 using the PhpUnit test class "PhpSyntax_PhpUnit.class.php". It is included in the download package. Once you're done you might want to check the PHP Cheat Sheet.


The following vars are set:

  var $empty       = '';
  var $null        = NULL;
  var $bool        = FALSE;
  var $notSet;
  var $array       = array();


empty (var $empty = "";)


1.  datatype of $empty?

2.  $x = empty($empty);
what is $x? true false

3.  $x = is_null($empty);
what is $x? true false

4.  $x = isSet($empty);
what is $x? true false

5.  $x = (bool)$empty;
what is $x? true false


null (var $null = NULL;)


6.  datatype of $null?

7.  $x = empty($null);
what is $x? true false

8.  $x = is_null($null);
what is $x? true false

9.  $x = isSet($null);
what is $x? true false

10.  $x = (bool)$null;
what is $x? true false


notSet (var $notSet;)


11.  datatype of $notSet?

12.  $x = empty($notSet);
what is $x? true false

13.  $x = is_null($notSet);
what is $x? true false

14.  $x = isSet($notSet);
what is $x? true false

15.  $x = (bool)$notSet;
what is $x? true false


array (var $array = array();)


16.  $x = empty($array);
what is $x? true false

17.  $x = is_null($array);
what is $x? true false

18.  $x = isSet($array);
what is $x? true false

19.  $x = (bool)$array;
what is $x? true false

20.  $x = (array('foo') == array('foo'));
what is $x? true false

21.  $x = (array('a'=>'foo') == array('b'=>'foo'));
what is $x? true false

22.  $arrOne = array(''=>'');
$arrTwo = array('9'=>'apple', '15'=>'banana', '20'=>'grapefruit');
$x = array_merge($arrOne, $arrTwo);

what is $x?
1) array(''=>'', 0=>'apple', 1=>'banana', 2=>'grapefruit');
2) array(''=>'', 9=>'apple', 15=>'banana', 20=>'grapefruit');


bool (var $bool = FALSE;)


23.  $x = empty($bool);
what is $x? true false

24.  $x = is_null($bool);
what is $x? true false

25.  $x = isSet($bool);
what is $x? true false


compare


26.  $x = (bool)($empty == $null);
what is $x? true false

27.  $x = (bool)($empty == $notSet);
what is $x? true false

28.  $x = (bool)($null == $notSet);
what is $x? true false

29.  $x = (bool)($empty === $null);
what is $x? true false

30.  $x = (bool)($empty === $notSet);
what is $x? true false

31.  $x = (bool)($null === $notSet);
what is $x? true false


string


32.  $x = (bool)("hello");
what is $x? true false

33.  $x = (bool)("15");
what is $x? true false

34.  $x = (bool)("0");
what is $x? true false

35.  $x = (bool)("-1");
what is $x? true false

36.  $x = (bool)("true");
what is $x? true false

37.  $x = (bool)("false");
what is $x? true false


number


38.  $x = (bool)(15);
what is $x? true false

39.  $x = (bool)(1);
what is $x? true false

40.  $x = (bool)(0);
what is $x? true false

41.  $x = (bool)(-1);
what is $x? true false


compare 2


42.  $x = (bool)("15" == 15);
what is $x? true false

43.  $x = (bool)("15" === 15);
what is $x? true false

44.  $x = (bool)("hello" == 15);
what is $x? true false

45.  $x = (bool)("hello" === 15);
what is $x? true false

46.  $x = (bool)("hello" == "true");
what is $x? true false

47.  $x = (bool)("hello" === "true");
what is $x? true false

48.  $x = (bool)("hello" == 1);
what is $x? true false

49.  $x = (bool)("hello" === 1);
what is $x? true false

50.  $x = (bool)("hello" == TRUE);
what is $x? true false

51.  $x = (bool)("hello" === TRUE);
what is $x? true false


datatype


52.  $x = (TRUE);
datatype of $x?

53.  $x = ("15" == 15);
datatype of $x?

54.  $x = ((TRUE) && (TRUE));
datatype of $x?

55.  $x = ((TRUE) AND (TRUE));
datatype of $x?

56.  $x = ((TRUE) || (TRUE));
datatype of $x?

57.  $x = ((TRUE) OR (TRUE));
datatype of $x?


reference


58.  $a = "hello";
$b = &$a;
$b = "world";

what is $a?

59.  $a = "hello";
$b = &$a;
unset($b);
$b = "world";

what is $a?

60.  $a = "hello";
$b = &$a;
unset($b);

what is $a?

61.  $a = "hello";
$b = &$a;
$b = "world";
unset($b);

what is $a?


pre post de increment


62.  $a = 1;
$b = $a++;

what is $b?

63.  $a = 1;
$b = ++$a;

what is $b?


pre post de increment (with reference)


64.  $a = 1;
$x = &$a;
$b = $a++;

what is $b?

65.  $a = 1;
$x = &$a;
$b = ++$a;

what is $b?


hash keys


66.  $a = 'foo';
$b = isSet($a['bar']);

what is $b? true false

67.  $a = 'foo';
$b = empty($a['bar']);

what is $b? true false

68.  $a = array('foo'=>'foo');
$b = isSet($a['bar']);

what is $b? true false

69.  $a = 1;
$b = isSet($a['bar']);

what is $b? true false



good luck :)