Chapter 3 - Introduction to PHP Flashcards
What does the GET method do?
Appennds the form data to the URL, changing the URL, by adding a query string.
By default, it follows the pattern ?value=property&value1=property1
Typically used when sending data to trigger a retrieval of more data
What does the POST method do?
Appends the form data inside the web request, thus not affecting the URL
Is theoretically limited only by the amount of data that PHP is set to accept and process
Typically used:
- when sending data for storage/analysis
- actions where the user will generally be forwarded back to the listing of sorts
Give a functionally complete tag:
On the display end, avoid styling tag directly, add additional markup (i.e.<div>) instead. This keeps the tag focused only on logic and removes it’s dependance on display
</div>
Once form data has been submitted, it is loaded onto what arrays?
$_GET annd $_POST
These are the first of the Superglobal arrays that PHP provides.
What makes arrays associative?
having strings for keys
What other array is populated, but should not be used over $_GET and _POST?
$_REQUEST
What is echo used for?
Used to output information from the script. It is not a proper function, and thus does not use parantheses.
Can strings be contained in double AND single quotes?
Yes, but quotes must match in order to complete a string.
Which quotes are unprocessed?
Single quotes are unprocessed - the contents are output verbatim.
Which quotes are processed?
Double quotes are processed for variables, processed for special characters.
Example:
$test “Hello World”;
echo ‘$test’;
OUTPUT: $test
echo “$test”;
OUTPUT: Hello World
How is concatenation performed in PHP?
With the . operator.
How is concatenation performed in PHP?
With the . operator.
Why should we be careful outputting user submitted information?
The browser does not have a concept of where data comes from, it just processes whatever test, HTML and JS it receives from the web server.
Use htmlspecialchars as a simple way of nullifying user submitted data.
How are comments added?
//this is a comment
What characters can you use to open and close comments almost anywhere to cover more than one line?
/* and */
How do you create an array in PHP?
$team = array(‘Bill’, ‘Mary’, ‘Mike’, ‘Chris’, ‘Anne’);
OR
array();
echo $team[3]; // Displays the name Chris
How do you create a two-dimensional array in PHP?
How do you create a two-dimensional array in PHP?
What are the four rules you must follow when creating PHP variables?
- Variable names must start with a letter of the alphabet or the _ (underscore) character.
- Variable names can contain only the characters a–z, A–Z, 0–9, and _ (underscore).
- Variable names may not contain spaces. If a variable must comprise more than one word, it should be separated with the _ (underscore) character (e.g., $user_name).
- Variable names are case-sensitive. The variable $High_Score is not the same as the variable $high_score.
Describe the magic constant LINE
The current line number of the file
Describe the magic constant FILE
The full path and filename of the file. If used inside an include, the name of the included file is returned. In PHP 4.0.2, __FILE__ always contains an absolute path with symbolic links resolved, whereas in older versions it might contain a relative path under some circumstances.
Describe the magic constant DIR
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)
Describe the magic constant
The function name. (Added in PHP 4.3.0.) As of PHP 5, returns the function name as it was declared (casesensitive). In PHP 4, its value is always lowercase.
Describe the magic constant __CLASS__
The class name. (Added in PHP 4.3.0.) As of PHP 5, returns the class name as it was declared (casesensitive). In PHP 4, its value is always lowercase.
Describe the magic constant __METHOD__
The class method name. (Added in PHP 5.0.0.) The method name is returned as it was declared (casesensitive).
Describe the magic constant __NAMESPACE__
The name of the current namespace (case-sensitive). This constant is defined at compile time. (Added in PHP 5.3.0.)