PHP Set 1 Flashcards
What are the steps for a web server processing a request that includes PHP?
- The web server receives a request from a client
- The web server recognizes the HTML document requested contains PHP code
- The server executes the PHP code, substitutes its output into the HTML document
- The resulting page is sent to the client
What are the two methods used to output in PHP?
echo and print
Do print and echo require parentheses to work?
No, you could do
echo “hello, world”
and it would work
What are the 8 datatypes that were included in PHP before version 8?
Primitive types
1. bool for booleans
2. int for integers
3. float for floating point numbers
4. string for strings
Compound types
1. array
2. object
Special types
1. resource
2. NULL
What is the difference in output for the strings ‘glass\table’ and “glass\table”?
‘glass\table’ outputs glass\table
“glass\table” outputs
glass able
because \t is the tab character
What are the 3 types of arrays in PHP?
- Indexed arrays which are arrays with a numeric index
- Associative arrays which are arrays with named keys like a dictionary
- Multidimensional arrays which are arrays that contain one or more arrays
What is the object type?
A data type which stores not only data but also information on how to process the data
What is the difference between converting from object to object and from array to object?
objects converted to other objects are not modified
When an array is converted to an object it will have properties named by keys and their corresponding values. For other values, a member variable named scalar will contain the value
What is the syntax for converting an array to an object?
$object = (object) $array;
What is the resource type?
A special data type that refers to an external resource. These resources are created and used by special functions
What is the NULL type?
Represents a variable with no value. null is the only possible value of type null
When is a variable considered to be null?
- It has been assigned the constant null
- It has not yet been set to any value
- It has been unset()
Empty arrays are considered to be null
What are the constants NAN and INF used for?
They are used as return values for some applications of mathematical functions that do not return a number.
For example log(0) will return -INF and sqrt(-1) will return NAN
What values of other types are considered false when converted to boolean?
- The boolean FALSE
- The integer 0
- The float 0.0
- The string ‘0’ but not ‘0.0’ or ‘00’
- The empty string “”
All other values are TRUE including any resource
What happens when you convert a boolean to a string?
TRUE becomes “1”
FALSE becomes “”