PHP Flashcards
What is a PHP script?
a file composed of HTML tags and PHP code inserted between<?php and ?>tags
What is a PHP Engine?
It compiles the requested PHP script and executes the code
What is contained in the php.ini file?
Configuration settings for PHP files
How is an echo statement used by a PHP script?
It produces output that is sent to the browser via HTTP response.
What setting in php.ini files controls error message generation?
error_reporting
What setting in php.ini files determines if error messages are sent to the browser??
display_errors
What are the four types of error messages in PHP?
- 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 are variables declared in PHP?
By initializing the variable.
What are the three rules for naming variables in PHP?
- Names must start with a $ symbol
- Can be any combination of letters, digits, or underscores
- May not start with a digit following the $
What is the difference between variable names, and functions / keyword names in PHP?
Variables are case sensitive, functions and keywords are not
How are PHP Constants different to variables?
- Constants cannot be changed
- Constants do not use $ in the name
- They are usually CAPITALIZED
How are PHP constants defined?
With the define(name, value) function or the const keyword
What is ‘variable interpolation’?
When the PHP engine substitutes the value of a variable for the variable name inside of a double-quoted string
What is the difference between double quoted and Single quoted strings in PHP?
- Single quotation strings disable variable interpolation.
- The only escape sequences in single quotation strings are // and /’
What is the PHP String concatenation operator?
A period
How does PHP handle strings encountered in an arithmetic expression?
- 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.
In addition to the standard compound assignment operators,what additional operators are present in PHP?
- %= Mod By
- .= Concatenation
What are the additional comparison operators in PHP vs Java?
- <> (inequality)
- === (identical: values and types must be the same)
- !== (Not Identical)
- <=> (Spaceship: acts as java equals() returning an int)
Does a PHP switch statement compare with == or ===?
==
What is a PHP array?
An ordered collection of key/value pairs.
Keys must be integers or strings, but values can be any datatype
What are the two types of PHP arrays?
- Indexed Array: Array with integer keys, similar to java array.
- Associative Array: String keys
What is the syntax of a foreach loop in PHP?
foreach($array as $value) {//body}
In a PHP associative array, what is the syntax for value assignment?
“key” => “value”
What are the 3 method pairs to sort PHP arrays?
- 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.
How are functions declared in PHP?
With the ‘function’ keyword.
Ex: function helloWorld() {//body}
How is case used in PHP function names?
Functions are case insensitive.
How are global variables accessed in PHP functions?
With the ‘global’ keyword.
Ex: global $variable;
Are PHP function arguments pass-by-value or pass-by-reference?
Pass-by-value
How are PHP function arguments made to be pass-by-reference?
With the ampersand character.
Ex: &$argVariable.
How are PHP method arguments given default values.
With the “=” operator.
Ex: method($variable = “defaul value”)
What is a variable length argument list in PHP?
A list of function arguments that can change in number.
How is a variable length argument list declared in PHP?
With the ‘…’ token.
Ex: …$args
What do PHP classes contain?
- Properties (variables defined in a class)
- Methods (functions defined in a class).
How are PHP class objects created?
With the “new” keyword.
How are PHP object properties / methods accessed?
With the object operator “->”.
Ex: $object->method()
How are a PHP object’s properties accessed within its methods?
With the “$this” variable and the object operator “->”.
Ex: $this->property
What is the function name of a PHP class constructor?
__construct
What is the function name of a PHP class destructor?
__destruct
How does a PHP class specify a parent class to inherit properties / methods?
With the “extends” keyword.
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.
How are static properties / methods accessed outside of PHP objects?
With the scope resolution operator “::”.
Ex: className::$staticVariable.
How are static properties / methods accessed within PHP objects?
With the “self” keyword and the scope resolution operator “::”.
Ex: self::staticMethod()
Which PHP function can parse a file into an array of strings?
preg_split
Which PHP function takes a string and parses it into an array?
explode(delimiter, string)
What PHP function takes an array and combines it together into a string?
implode(delimiter, array)
What PHP function reads a file and returns the contents as a string?
file_get_contents(file_path)