PHP Set 4 Flashcards

1
Q

What is the rule for naming functions?

A

Must start with a letter or an underscore

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

Are function names case sensitive?

A

No they are not.
Ex: If you have a function called writeMsg() you could call it with WritemsG(); and it would still work

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

What are the 4 variable scopes that are available in PHP?

A
  1. Local variables: Only valid in the part of the code they are introduced
    a. Variables inside a function are local inside the function’s curly braces
  2. Global variables that are valid outside of functions
    a. Variables outside any function are global
  3. Superglobal variables are built-in variables that are always available in all scopes
  4. Static variables are local variables that retain their value between separate calls of the function
    a. Static variables should always be initialized with a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you include HTML markup in the body of a PHP function definition?

A

<?php
function html_output() {
?>
<h1>HELLO<h1>
<p>This is HTML<p>
<?php
}
html_output();
?>

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

How can you pass in a variable reference and what is the difference from passing in a variable value?

A

Using ‘&’ like &$var1
When passing in a variable by reference, changes to the argument also change the variable that was passed in. If you only pass by value the variable is not modified outside of the function scope

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

How can you pass in a variable number of arguments to a function and how is it handled by PHP?

A

Using ‘…’ such as function sum(…$numbers) denotes a function that accepts a variable number of arguments. The arguments are passed into the given variable as an array

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

What is an anonymous function?

A

Also known as closures, they are functions that have no specified function name but still have inputs and an output. You can assign an anonymous function to a variable

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

Can functions be passed to other functions as arguments?

A

Yes they can
Ex: function apply ($f ,$x ,$y) {
return $f($x ,$y );
}
where $f is a function argument

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

What is the difference between include and require when importing a file to a PHP script?

A

If a file is not found when it is required it will throw an E_COMPILE_ERROR and will halt the script
If a file is not found when it is included it will throw a warning but the rest of the script will run

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

What is the difference between include and include_once when importing a file to a PHP script?

A

include_once will not include the code from a file if that code has already been included. It is used where the same file might be included and evaluated more than once during execution of a script

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