PHP Flashcards

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
Q

How are functions declared in PHP?

A

With the ‘function’ keyword.
Ex: function helloWorld() {//body}

26
Q

How is case used in PHP function names?

A

Functions are case insensitive.

27
Q

How are global variables accessed in PHP functions?

A

With the ‘global’ keyword.
Ex: global $variable;

28
Q

Are PHP function arguments pass-by-value or pass-by-reference?

A

Pass-by-value

29
Q

How are PHP function arguments made to be pass-by-reference?

A

With the ampersand character.
Ex: &$argVariable.

30
Q

How are PHP method arguments given default values.

A

With the “=” operator.
Ex: method($variable = “defaul value”)

31
Q

What is a variable length argument list in PHP?

A

A list of function arguments that can change in number.

32
Q

How is a variable length argument list declared in PHP?

A

With the ‘…’ token.
Ex: …$args

33
Q

What do PHP classes contain?

A
  • Properties (variables defined in a class)
  • Methods (functions defined in a class).
34
Q

How are PHP class objects created?

A

With the “new” keyword.

35
Q

How are PHP object properties / methods accessed?

A

With the object operator “->”.
Ex: $object->method()

36
Q

How are a PHP object’s properties accessed within its methods?

A

With the “$this” variable and the object operator “->”.
Ex: $this->property

37
Q

What is the function name of a PHP class constructor?

A

__construct

38
Q

What is the function name of a PHP class destructor?

A

__destruct

39
Q

How does a PHP class specify a parent class to inherit properties / methods?

A

With the “extends” keyword.

40
Q

What are the access modifiers of PHP class properties / methods?

A
  • public: the default when no modifier is stated
  • protected: only accessible by class or children.
  • private: only accessible by defining class.
41
Q

How are static properties / methods accessed outside of PHP objects?

A

With the scope resolution operator “::”.
Ex: className::$staticVariable.

42
Q

How are static properties / methods accessed within PHP objects?

A

With the “self” keyword and the scope resolution operator “::”.
Ex: self::staticMethod()

43
Q

Which PHP function can parse a file into an array of strings?

A

preg_split

44
Q

Which PHP function takes a string and parses it into an array?

A

explode(delimiter, string)

45
Q

What PHP function takes an array and combines it together into a string?

A

implode(delimiter, array)

46
Q

What PHP function reads a file and returns the contents as a string?

A

file_get_contents(file_path)