Show Menu
Cheatography

functions Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Functions construct

The constructs for(), foreach(), and each() can all be used to iterate an object if the object...
A. implements ArrayA­­ccess
B. implements Iterator
C. implements Iterator and ArrayA­­ccess
D. None of the above
Answer : C

Functions

Which PHP function is used to validate whether the contents of
$_FILE­­S[­'­n­am­­e']­­['­t­m­p_­­name'] have really been uploaded via HTTP, and also save the contents into another folder?
Answer : move_u­­pl­o­a­de­­d_f­­ile(), move_u­­pl­o­a­de­­d_file

Functions

Which PHP function sets a cookie and URL encodes its value when sending it to the
browser?
Answer: setcookie, setcoo­kie()

Functions

Which PHP function sets a cookie whose value does not get URL encoded when sending it to the browser?
setraw­­co­okie, setraw­­co­o­kie()

Functions

What function can reverse the order of values in an array so that keys are preserved?

A. array_­­flip()
B. array_­­re­v­e­rse()
C. rsort()
D. krsort()
E. array_­­mu­l­t­is­­ort()
Answer: B

Functions

PHP's array functions such as array_­­va­l­ues() can be used on an object if the object...

A. implements Traver­­sable
B. is an instance of ArrayO­­bject
C. implements ArrayA­­ccess
D. None of the above
Answer: D

Functions

You need to escape special characters to use user input inside a regular expres­­sion.
Which functions would you use? (Choose 2)
A. addsla­­shes()
B. htmlen­­ti­t­ies()
C. preg_q­­uote()
D. regex_­­qu­ote()
E. quote_­­meta()
Answer: C, E

Functions

Which function can NOT help prevent cross-site scripting? (Choose 2)
A. addsla­­shes()
B. htmlen­­ti­t­ies()
C. htmlsp­­ec­i­a­lc­­hars()
D. strip_­­tags()
E. quotem­­eta()
Answer: A, E

Functions

Which of these error types may be handled by user defined error handler function?

A. E_ERROR
B. E_NOTICE
C. E_PARSE
D. E_WARNING
Answer: A, C

Functions

You want to allow your users to submit HTML code in a form, which will then be displayed
as real code and not affect your page layout. Which function do you apply to the text, when
displaying it? (Choose 2)
A. strip_­­tags()
B. htmlen­­ti­t­ies()
C. htmltidy()
D. htmlsp­­ec­i­a­lc­­hars()
E. showhtml()
Answer: B, D

Functions

You want to parse a URL into its single parts. Which function do you choose?

A. parse_­­url()
B. url_pa­­rse()
C. get_ur­­l_­p­a­rts()
D. geturl­­pa­rts()
Answer: A

Functions

Which of the following functions are used to escape data within the context of HTML?
(Choose 2)
A. htmlen­­ti­t­ies()
B. addsla­­shes()
C. strips­­la­s­hes()
D. strip_­­tags()
E. htmlsp­­ec­i­a­lc­­hars()
Answer : A,E

Functions

What will the following function call print?
printf­­('­%­0­10.6f', 22);
A. 22
B. 22.00
C. 022.000000
D. 22.000000
Answer : C

Functions

Which elements does the array returned by the function pathinfo() contain?
A. root, dir, file
B. dirname, filename, fileex­­te­nsion
C. dirname, basename, extension
D. path, file
Answer: C

Comparison func and operator

What is the difference between the spaceship operator (<=­­>) and the strcmp() function?

A. There is no difference in functi­­on­ality
B. strcmp() returns a Boolean value, the spaceship operator a number
C. strcmp() does a case-i­­nt­e­nsive compar­­ison, the spaceship operator does not
D. The spaceship operator returns -1, 0 or 1; strcmp() may return any integer
Answer : D
 

Anonimous Functions

Which of the following statements about anonymous functions in PHP are NOT true? (Choose 2)

A. Anonymous functions can be bound to objects
B. Anonymous functions created within object context are always bound to that object
C. Assigning closure to a property of an object binds it to that object
D. Methods bind() and bindTo() of the Closure object provide means to create closures with different binding and scope
E. The binding defines the value of $this and the scope for a closure
Answer: B,C

Functions

What function allows resizing of PHP's file write buffer?

A. ob_start()
B. set_wr­­it­e­_­bu­­ffer()
C. stream­­_s­e­t­_w­­rit­­e_­b­u­ffer()
D. Change the output­­_b­u­f­fering INI setting via ini_set() function
Answer: C

Functions

Which constant must be passed as the second argument to htmlen­­ti­t­ies() to convert single
quotes (') to HTML entities?

A. TRUE
B. FALSE
C. ENT_QUOTES
D. ENT_NO­­QUOTES
E. ENT_COMPAT
Answer: C

Functions

What is the name of the PHP function used to automa­­ti­cally load non-yet defined classes?

A. autoload()
B. _ _auto­­load()
C. _ _catch()
D. load()
E. loadCl­­ass()
Answer: B

Functions

Which PHP function retrieves a list of HTTP headers that have been sent as part of the
HTTP response or are ready to be sent?
A. header()
B. headers()
C. header­­s_­l­ist()
D. header­­s_­s­ent()
E. getres­­po­n­s­eh­­ead­­ers()
Answer: C

Functions

What is the name of the function that allows you register a set of functions that implement
user-d­­efined session handling?
A. sessio­­n_­s­e­t_­­han­­dler()
B. sessio­­n_­s­e­t_­­sto­­ra­g­e­_h­­and­­ler()
C. sessio­­n_­r­e­gi­­ste­­r_­h­a­nd­­ler()
D. sessio­­n_­s­e­t_­­sav­­e_­h­a­nd­­ler()
Answer: D

Functions

What function is best suited for extracting data from a formatted string into an array?

A. fgetcsv
B. sscanf
C. sprintf
D. strtok
Answer : C

Functions

What function can be used to retrieve an array of current options for a stream context?
A. stream­­_c­o­n­te­­xt_­­ge­t­_­params
B. stream­­_c­o­n­te­­xt_­­ge­t­_­de­­fault
C. stream­­_c­o­n­te­­xt_­­ge­t­_­op­­tions
D. The 'options' element of the stream­­_g­e­t­_m­­eta­­_data return value
Answer : C

Functions

Which of the following is NOT a valid function declar­­ation?

A. function x ($x1= array())
B. function x (A $x1)
C. function x (A $x1 = null)
D. function x ($x1 = $x2)
Answer : D

Functions

Which of the following PHP functions can be used to set the HTTP response code? (­chosee 2)

A. header­­_add()
B. header()
C. http_s­­et­_­s­ta­­tus()
D. http_r­­es­p­o­ns­­e_c­­ode()
E.http­­_h­e­a­de­­r_set()
Answer: B, D

Functions

Which PHP function is uses to validate wheather the contents of $_FILE­­S[­'­n­am­­e']­­['­t­m­p_­­name'] have relly been uploaded via HTTP?
Answer : is_upl­­oa­d­e­d_­­file(), is_upl­­oa­d­e­d_file

Functions

How do you allow the caller to submit a variable number of arguments to a function?

A. Using a prototype like function test(... $param­­et­ers).
B. Using a prototype like function test() and the function func_g­­et­_­a­rgs() inside the function body.
C. Using a prototype like function test($­­pa­r­a­me­­ter­­s[]).
D. Using a prototype like function test() and the function get_va­­ri­a­b­le­­_args() inside the function body.
E. This is not possible in PHP.
Answer : B

Comparison func and operator

What is the difference between the spaceship operator (<=­­>) and the strcmp() function?

A. There is no difference in functi­­on­ality
B. strcmp() returns a Boolean value, the spaceship operator a number
C. strcmp() does a case-i­­nt­e­nsive compar­­ison, the spaceship operator does not
D. The spaceship operator returns -1, 0 or 1; strcmp() may return any integer
Answer : D

Functions

Which of the following functions will allow identi­­fying unique values inside an array?
A. array_­­un­i­q­ue­­_values
B. array_­­di­s­tinct
C. array_­­co­u­n­t_­­values
D. array_­­in­t­e­rsect
E. array_­­values
Answer : C