PHP Flashcards

(46 cards)

1
Q

What is a PHP script?

A

a file composed of HTML tags and PHP code inserted between<?php and ?>tags

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

What is a PHP Engine?

A

It compiles the requested PHP script and executes the code

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

What is contained in the php.ini file?

A

Configuration settings for PHP files

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

How is an echo statement used by a PHP script?

A

It produces output that is sent to the browser via HTTP response.

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

What setting in php.ini files controls error message generation?

A

error_reporting

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

What setting in php.ini files determines if error messages are sent to the browser??

A

display_errors

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

What are the four types of error messages in PHP?

A
  • Parse Error: Syntax error when code is compiled
  • Fatal Error: Runtime Error that halts execution
  • Warning: Runtime error that doesn’t halt execution
  • Notice: Runtime message of possible logic error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are variables declared in PHP?

A

By initializing the variable.

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

What are the three rules for naming variables in PHP?

A
  • Names must start with a $ symbol
  • Can be any combination of letters, digits, or underscores
  • May not start with a digit following the $
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between variable names, and functions / keyword names in PHP?

A

Variables are case sensitive, functions and keywords are not

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

How are PHP Constants different to variables?

A
  • Constants cannot be changed
  • Constants do not use $ in the name
  • They are usually CAPITALIZED
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are PHP constants defined?

A

With the define(name, value) function or the const keyword

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

What is ‘variable interpolation’?

A

When the PHP engine substitutes the value of a variable for the variable name inside of a double-quoted string

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

What is the difference between double quoted and Single quoted strings in PHP?

A
  • Single quotation strings disable variable interpolation.
  • The only escape sequences in single quotation strings are // and /’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the PHP String concatenation operator?

A

A period

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

How does PHP handle strings encountered in an arithmetic expression?

A
  • The string converted into an int
  • Strings with “E” or “e” are evaluated as scientific notation.
  • A string with leading digits can be converted into a number, but PHP generates a warning.
  • Attempting arithmetic with a string that has no leading digits causes a fatal error.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In addition to the standard compound assignment operators,what additional operators are present in PHP?

A
  • %= Mod By
  • .= Concatenation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the additional comparison operators in PHP vs Java?

A
  • <> (inequality)
  • === (identical: values and types must be the same)
  • !== (Not Identical)
  • <=> (Spaceship: acts as java equals() returning an int)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Does a PHP switch statement compare with == or ===?

20
Q

What is a PHP array?

A

An ordered collection of key/value pairs.
Keys must be integers or strings, but values can be any datatype

21
Q

What are the two types of PHP arrays?

A
  • Indexed Array: Array with integer keys, similar to java array.
  • Associative Array: String keys
22
Q

What is the syntax of a foreach loop in PHP?

A

foreach($array as $value) {//body}

23
Q

In a PHP associative array, what is the syntax for value assignment?

A

“key” => “value”

24
Q

What are the 3 method pairs to sort PHP arrays?

A
  • sort() / rsort(): sort indexed arrays in ascending / descending order
  • asort() / arsort(): sort associative arrays based on values in ascending / descending order.
  • ksort() / krsort(): sort associative arrays based on keys in ascending / descending order.
25
How are functions declared in PHP?
With the 'function' keyword. Ex: function helloWorld() {//body}
26
How is case used in PHP function names?
Functions are case insensitive.
27
How are global variables accessed in PHP functions?
With the 'global' keyword. Ex: global $variable;
28
Are PHP function arguments pass-by-value or pass-by-reference?
Pass-by-value
29
How are PHP function arguments made to be pass-by-reference?
With the ampersand character. Ex: &$argVariable.
30
How are PHP method arguments given default values.
With the "=" operator. Ex: method($variable = "defaul value")
31
What is a variable length argument list in PHP?
A list of function arguments that can change in number.
32
How is a variable length argument list declared in PHP?
With the '...' token. Ex: ...$args
33
What do PHP classes contain?
- Properties (variables defined in a class) - Methods (functions defined in a class).
34
How are PHP class objects created?
With the "new" keyword.
35
How are PHP object properties / methods accessed?
With the object operator "->". Ex: $object->method()
36
How are a PHP object's properties accessed within its methods?
With the "$this" variable and the object operator “->”. Ex: $this->property
37
What is the function name of a PHP class constructor?
__construct
38
What is the function name of a PHP class destructor?
__destruct
39
How does a PHP class specify a parent class to inherit properties / methods?
With the "extends" keyword.
40
What are the access modifiers of PHP class properties / methods?
- public: the default when no modifier is stated - protected: only accessible by class or children. - private: only accessible by defining class.
41
How are static properties / methods accessed outside of PHP objects?
With the scope resolution operator "::". Ex: className::$staticVariable.
42
How are static properties / methods accessed within PHP objects?
With the "self" keyword and the scope resolution operator "::". Ex: self::staticMethod()
43
Which PHP function can parse a file into an array of strings?
preg_split
44
Which PHP function takes a string and parses it into an array?
explode(delimiter, string)
45
What PHP function takes an array and combines it together into a string?
implode(delimiter, array)
46
What PHP function reads a file and returns the contents as a string?
file_get_contents(file_path)