php_zend_cert Flashcards

1
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

PHP_START_TAG

$array1 = $array2 = array(“img12.png”, “img10.png”, “img2.png”, “img1.png”); asort($array1); var_dump($array1); PHP_END_TAG

doesn’t sort in an order a human would expect. What function should we use instead ?

A

bool natsort ( array &$array ) will output array 3 => string ‘img1.png’ (length=8) 2 => string ‘img2.png’ (length=8) 1 => string ‘img10.png’ (length=9) 0 => string ‘img12.png’ (length=9)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

PHP_START_TAG $chaine = “Hello World”; $bool = ( $chaine[1] === $chaine{1} ); PHP_END_TAG What is the value of $bool ?

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PHP_START_TAG $details[] = ‘Mehdi’; $details[] = ‘Matthieu’; $details[] = ‘cuillère’; … echo “$nom1 et $nom2 mangent à l’aide d’une $ustensile
“; PHP_END_TAG Write the missing line that will allow a correct display.

A

list ($nom1, $nom2, $ustensile) = $details;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=-2; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?

A

array 0 => string ‘la’ (length=2) 1 => string ‘li’ (length=2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=0; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?

A

array 0 => string ‘la–li–lou–la–lo’ (length=19) If the limit parameter is zero, then this is treated as 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

PHP_START_TAG $long = ‘la–li–lou–la–lo’; $delimiter=’–’; $limit=3; $explodedArray = explode($delimiter,$long,$limit); PHP_END_TAG What does $explodedArray contain ?

A

array 0 => string ‘la’ (length=2) 1 => string ‘li’ (length=2) 2 => string ‘lou–la–lo’ (length=11)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

PHP_START_TAG $numbers = array(“0”, “1”, “2”, “3”); $value= 2 ; echo (in_array ( $value , $numbers ,TRUE ) ? “$value is a number” : “$value is not a number”); PHP_END_TAG What does this code display ?

A

2 is not a number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PHP_START_TAG $os = array(“Mac”, “NT”, “Irix”, “Linux”); echo (in_array ( “mac” , $os ) ? ‘mac is an OS’ : ‘mac is not an OS’); PHP_END_TAG What does this code display ?

A

mac is not an OS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

PHP_START_TAG $search_array = array(‘first’ => null, ‘second’ => 4); $returnValue = array_key_exists(‘first’, $search_array); PHP_END_TAG What is the value of $returnValue ?

A

true. You should use isset($search_array[‘first’]) if you want to return false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

PHP_START_TAG $subject = “pitimi bilipi waowao ao wawao pikin iki owawa”; $mask = “aow”; $longueurPermierWawa = strspn ( $subject , $mask , …. ); echo $longueurPremierWawa; PHP_END_TAG How should I complete this code in order to correctly use strspn() ?

A

strpos($subject, ‘w’) Fo reference, int strspn ( string $subject , string $mask [, int $start [, int $length]] ) $start and $length can have negative values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

PHP_START_TAG $var = ‘lala’ if ( gettype ( $var ) == ‘lala’) {echo “$var is a string”;} PHP_END_TAG Is there a better way to do the same thing ?

A

Use is_string();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

PHP_START_TAG function incrementVariable() { static $nb = 0; $nb++; return $nb; } echo incrementVariable(); incrementVariable(); PHP_END_TAG What does this code display ?

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

PHP_START_TAG while (true) { while (true) { … } } PHP_END_TAG What instruction can you write do get out of the loop ?

A

break(2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can PHP include distant files ?

A

Yes, with allow_url_fopen set to 1 in php.ini. But default is 0. It cannot be changed with ini_set()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Cite a function that generates a random number.

A

int mt_rand ( int $min =0 , int $max = mt_getrandmax() ) int rand ( void ) int rand ( int $min , int $max )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Cite the three functions that allow your function to access the passed arguments.

A

int func_num_args(void) mixed func_get_arg(int $arg_num ) array func_get_args ( void )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Give an easy way to filter user input.

A

string strip_tags ( string $str [, string $allowable_tags] ) Because strip_tags() does not actually validate the HTML, partial, or broken tags can result in the removal of more text/data than expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Has PHP got a pointer system ?

A

No, not like C. It uses reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Hopw do you delete a folder ?

A

bool rmdir ( string $dirname [, resource $context] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How are NULL, FALSE and numbers equal to 0 transtyped into a string ?

A

They are transtyped to an empty string (not to the 0 char)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How are sessions saved ?

A

depends on session.save_handler in php.ini. Generally, session.save_handler=’files’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How could you access a variable outside of its normal scope

A

Use superglobal array $GLOBALS[]. Use of register_globals is deprecated, and set to off in PHP.ini

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do I check if a variable is an array ?

A

is_array($var)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do I check if a variable is an object ?

A

is_object()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How do I know the data type of a variable ?

A

gettype($var) or is_string($var) is_bool($var) is_int($var) is_integer($var) etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How do transtype a variable’s value into another variable

A

strval(), intval(), doubleval(), floatval(), etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How do you calculate the sum of values in an array ?

A

number array_sum ( array $array )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

How do you check if the given key or index exists in the array ?

A

bool array_key_exists ( mixed $key , array $search )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How do you check if the object or class has a given property ?

A

bool property_exists ( mixed $class , string $property ) $class : The class name OR an object of the class to test for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How do you convert \n character to HTML ?

A

nl2br()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

How do you convert all applicable characters to HTML entities ? What parameter defines the applicable charset ?

A

string htmlentities ( string $string [, int $flags = ENT_COMPAT [, string $charset [, bool $double_encode = true]]] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

How do you count all the different values of an array ?

A

array array_count_values ( array $input ) Returns an associative array using the values of $input as keys and their frequency as values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

How do you create a constant ?

A

define(“CONSTANT”,”value”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

How do you delete a file ?

A

bool unlink ( string $filename [, resource $context] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

How do you destroy a variable ?

A

unset($var)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How do you do?

A

Splendid !

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

How do you force a variable to be transtyped ?

A

* (int), (string), etc, before the variable * settype($variable, $dataType)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

How do you make a copy of an object ?

A

$copy = clone $original;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

How do you merge arrays ?

A

array array_merge( array $array1 [, array $array2 [, array $…]] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

How do you merge the elements of one or more arrays together so that the values of one are appended to the end of the previous one ?

A

array array_merge ( array $array1 [, array $array2 [, array $…]] ) If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

42
Q

How do you recreate a session idea (and force a user to have his own) ?

A

bool session_regenerate_id ([bool $delete_old_session = false] )

43
Q

How do you split a string into chunks in an array ?

A

array explode ( string $delimiter , string $string [, int $limit] )

44
Q

How do you test whether a String is empty ?

A

empty() ( isset() will return TRUE )

45
Q

In an array, how do you make keys become values and values become keys ?

A

array array_flip ( array $trans ) Keys from trans become values and values from trans become keys. Values of trans need to be valid keys, i.e. they need to be either integer or string. Otherwise warning and not flipped. If a value has several occurrences, the latest key will be used as its values, and all others will be lost.

46
Q

In what case is !$a evaluated to TRUE ?

A

When $a is not TRUE

47
Q

Is E_STRICT a higher form of error detection than E_ALL ?

A

E_STRICT is a new level of errors in PHP5. It is not included in E_ALL. Therefore error_reporting is often set to E_ALL | E_STRICT

48
Q

Name 3 magic methods.

A

for example : __construct() __destruct() __autoload() __set() __get() __call() __sleep() __wakeup() __toString() __clone()

49
Q

PHP.ini : what is the directive that specifies whether errors are displayed or not ?

A

display_errors (= Off in production)

50
Q

Transtyping : what different variables, with other data types, can be automatically transtyped to boolean false ?

A

* the FALSE constant * the NULL constant * an empty string * 0 (int) * 0 (float) * the “0” string * an empty array

51
Q

What are the arguments of str_ replace() ?

A

mixed str_replace ( mixed $search , mixed $replacement , mixed $haystack [, int &$count] ) $haystack can be an array, in which case str_replace() returns an array.

52
Q

What are the arguments of strreplace() ?

A

This function doesn’t exist ! It is spelt str_replace() !

53
Q

What are the data types available in PHP?

A

*bool *integer *float (or double??) *string

54
Q

What are the differences between require() and include() ?

A

include() includes the file dynamically. Return a warning if error occurs. require() does not re-evaluate the content of the file if called another time. Creates an error if fails.

55
Q

What are the parameters of str_word_count ( ) ?

A

string $string [, int $format = 0 [, string $charlist]] $format * 0 - returns the number of words found * 1 - returns an array containing all the words found inside the string * 2 - returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself $charlist A list of additional characters which will be considered as ‘word’

56
Q

What are the php.ini parameter that allow you to able or disable tags

A

short_tags asp_tags

57
Q

What are the three variants of strpos() ?

A

stripos() strrpos() strripos()

58
Q

What does PHP_START_TAG echo ‘l'antislash : \’; PHP_END_TAG display ?

A

l’antislash : \

59
Q

What does PHP_START_TAG echo ‘l\x20o’; PHP_END_TAG display?

A

It displays l\x20o PHP_START_TAG echo “l\x20o”; PHP_END_TAG would display the letter ‘l’,a whitespace, and the letter ‘o’.

60
Q

What does strip_tags do?

A

string strip_tags ( string $str [, string $allowable_tags] ) $allowable_tags should not contain whitespaces. This function tries to return a string with all NUL bytes, HTML and PHP tags stripped from a given str. It uses the same tag stripping state machine as the fgetss() function. ( resource $handle [, int $length [, string $allowable_tags]] )

61
Q

What does this code dislpay ? PHP_START_TAG function &incrementVariable(&$value) { $value = $value + 2; return $value; } $var = 0; $ref = &incrementVariable($var); $ref++; echo $var; PHP_END_TAG

A

3

62
Q

What does this code display ? PHP_START_TAG $var1= 1 + “3 petits cochons”; $var2 = 1 + “un certain nombre de petits cochons”; echo $var1 + $var2; PHP_END_TAG

A

5

63
Q

What does this code display ? PHP_START_TAG $a = FALSE; $b = “”; echo ($a!=$b) ? ‘$a is different from $b’ : ‘$a is the same as $b’; echo ‘
‘; echo ($a!==$b) ? “$a is different from $b” : “$a is the same as $b”; PHP_END_TAG

A

$a is the same as $b is different from

64
Q

What does this code display ? PHP_START_TAG $newstring = ‘abcd abcd’; echo $pos = strpos($newstring, ‘b’, 2); PHP_END_TAG

A

6

65
Q

What does this code display ? PHP_START_TAG $objet = new stdClass(); $type = new stdClass(); $type->titre = “Comte de Monte Christo”; $objet->type = “livre”; echo “Le titre de ce $objet->type est {$objet->type}->titre”; PHP_END_TAG

A

Le titre de ce livre est livre->titre

66
Q

What does this code display ? PHP_START_TAG $one = 1; $two = 2; $three = 3; $four = 4; echo ( ($two<<$three) - (~$four & 3) ) ^ $one; PHP_END_TAG

A

12 The ‘3’ in (~$four & 3) allows to do the ‘~’ operation on the right number of bits

67
Q

What does this code display ? PHP_START_TAG $one = 1; $two = 2; echo $one | $two ; PHP_END_TAG

A

3 (binary operator : 01 | 10)

68
Q

What does this code display ? PHP_START_TAG $origine = “Hello World”; $reference =& $origine; unset($origine); echo $reference; PHP_END_TAG

A

Hello World

69
Q

What does this code display ? PHP_START_TAG $string = “Madame Kosciusko-Morizet dit : Insh’Allah”; echo str_word_count($string); PHP_END_TAG

A

4

70
Q

What does this code display ? PHP_START_TAG $url = ‘http://fr2.php.net/manual/en/function.parse-url.php’; $parsedURL = parse_url($url); var_dump($parsedURL); PHP_END_TAG

A

array ‘scheme’ => string ‘http’ (length=4) ‘host’ => string ‘fr2.php.net’ (length=11) ‘path’ => string ‘/manual/en/function.parse-url.php’ (length=33) mixed parse_url ( string $url [, int $component = -1] )

71
Q

What does this code display ? PHP_START_TAG $var1= 1 + “3 petits cochons”; $var2 = 1 + “un certain nombre de petits cochons”; echo $var1 + $var2; PHP_END_TAG

A

5

72
Q

What does this code display ? PHP_START_TAG class foo { private $a; public $b = 1; static $c; public function test() { var_dump(get_object_vars($this)); } } $test = new foo; $test->test(); PHP_END_TAG

A

array ‘a’ => null ‘b’ => int 1

73
Q

What does this code display ? PHP_START_TAG function &incrementVariable(&$value) { $value= $value + 2 ; return $value; } $var = 0; $ref = incrementVariable($var); $ref++; echo $var; PHP_END_TAG

A

2

74
Q

What does this code display ? PHP_START_TAG function incrementVariable(&$value) { $value = $value + 2; return $value; } $var = 0; $ref = &incrementVariable($var); $ref++; echo $var; PHP_END_TAG

A

2

75
Q

What does this code display ? PHP_START_TAG if ( ! substr(“abcdef”, 4, -4) ) { echo strcmp ( substr(“abcdef”, -4, 3) , substr(“abcdef”, 2, -1) ); } PHP_END_TAG

A

0 string substr ( string $string , int $start [, int $length] ) start and length can be negative.

76
Q

What does this code display ? PHP_START_TAG printf(‘%-06b’, 15); PHP_END_TAG

A

111100 i.e. writes out a number with 6 digits, using 1111 and adding remaining zeros on the right (because of ‘-‘)

77
Q

What does this code display ? PHP_START_TAG printf(‘%08f’, 1.01); PHP_END_TAG

A

001.0100

78
Q

What does this code display ? PHP_START_TAG printf(‘-%10s’, ‘papipu’); PHP_END_TAG

A
  • papipu papipu : 6 characters %10s : will write out 10 characters, using the string provided as parameter 10 - 6 => 4 whitespace characters are created by the function to fill up to 10.
79
Q

What does this piece of shitty code display ? PHP_START_TAG $montexte1 = “Salut”; $montexte2 = “tout le monde”; $var1 = 2; $var2 = 5; $texte =<<
$montexte1\x20$montexte2 var1; echo $texte; PHP_END_TAG

A

2 = 2 + 5; $var1 = 2 = “2” Voici donc mon texte
Salut tout le monde This is HEREDOC syntax

80
Q

What function returns the first occurrence of a string in another string and returns the portion of string if found ?

A

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false] ) case-insensitive : stristr() from right to left : strrchr()

81
Q

What happens if an Exception thrown in a try block is not caught by a brother catch block.

A

It is sent to parent try/catch block. The subsequent code on the same level as the original try/catch blocks will not be executed.

82
Q

What is the function that return the length of a string ?

A

strlen()

83
Q

What is the instruction, inside a loop, that skips the code to the next iteration ?

A

continue

84
Q

What is the only error that cannot be treated/retrieved ?

A

parse error

85
Q

What is the parameter that escapes all input into the script and what is its common default value

A

magic_quotes_gpc = Off DEPRECATED

86
Q

What is the php.ini parameter thats determines the error level ?

A

error_reporting

87
Q

What is the problem with this code ? PHP_START_TAG $string = “@mcclown.com”; $searchString = “@m”; $pos = strpos($string , $searchString); if (!$pos) { echo “‘$searchString’ was not found in ‘$string’”; } PHP_END_TAG

A

!$pos is evaluated as FALSE, because $pos = 0; It should be written : if ($pos === FALSE)

88
Q

What is the purpose of dirname() ?

A

string dirname ( string $path ) : this function will return the parent directory’s path, given a string containing the path of a file or directory.

89
Q

What is the purpose of Safe Mode ?

A

Limit user access : created for shared-server security, but DEPRECATED

90
Q

What is the return value of strcmp ( string $str1 , string $str2 ) ?

A

Returns < 0 if str1 is less than str2 Returns > 0 if str1 is greater than str2 Returns 0 if they are equal.

91
Q

What is the reverse function of string chr(int) ?

A

int ord ( string $string )

92
Q

What is the value of $bodyTag ? PHP_START_TAG $bodytag = str_replace(“%body%”, “black”, “”); PHP_END_TAG

A

It would display if it had been str_ireplace()

93
Q

What is the value of $x ? PHP_START_TAG $x = 010 + 0x10; PHP_END_TAG

A

24

94
Q

What is the value of $x ? PHP_START_TAG $x = 015 + 1; PHP_END_TAG

A

14 (015 in octal base = 13 in decimal)

95
Q

What is the value that should be assigned to error_reporting during development ?

A

E_ALL | E_STRICT

96
Q

What modules are used to make conversions between character sets ?

A

iconv voir string iconv( string $in_charset , string $out_charset , string $str mbstring voir output_handler = mb_output_handler ; mb_convert_encoding() mb_convert_variables()

97
Q

What operator is evaluated first ? $a & $b == true

A

$b == true

98
Q

What other way can I write $var ?

A

${“var”} ${“v” . “ar”} etc

99
Q

What situation is sqlLite most suited for ?

A

Data not too big : stocked in server RAM

100
Q

When does the use of an unitialised variable create an error ?

A

When error_reporting is E_ALL

101
Q

When I want to create an INSERT statement, how do I convert end of line characters, carriage return characters, and non-grammatical ascii characters ?

A

addcslashes() addslashes() only escapes ‘ “ and \

102
Q

Which of : * $-myvariable * $var;iable * $@variable * $2variable is a valid variable name?

A

N one