Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
128 Cards in this Set
- Front
- Back
PHP is a...
|
a server scripting language executed on the server.
|
|
PHP stands for:
|
PHP Hypertext Preprocessor
|
|
PHP is open source?
|
Yes
|
|
What is the PHP file extension?
|
.php
|
|
What can PHP do?
|
generate dynamic page content
create, open, read, write, and close files on the server collect form data send and receive cookies add, delete, modify data in your database restrict users to access some pages on your website encrypt data |
|
_SESSION
|
A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
|
|
How to start destroy the session
|
session_start();
session_destroy(); |
|
_SERVER
|
an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.
http://php.net/manual/en/reserved.variables.server.php |
|
PHP script tags
|
<?php
// PHP code goes here ?> |
|
PHP COmments
|
// This is a single line comment
# This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ |
|
What parts of PHP are case insensitive?
|
INSENSITIVE: functions, classes, keywords
SENSITIVE: variables |
|
PHP has X scope types?
|
3.
local global static |
|
PHP local scope
|
Variable declared inside a function
|
|
PHP global scope
|
Variable declared outside a function, in the main script block
|
|
Can functions see global variables?
|
Yes, only if they define them locally using the 'global' keyword
|
|
What does the global keyword do?
|
Allows access of global variables from with functions.
|
|
2 ways functions can access global variables?
|
1. Use the 'global' keyword
2. Use the GLOBALS super array |
|
What does the static keyword do?
|
Used when declaring function variables. They variable is initialized once and persisted between function calls.
Does not impact scope. |
|
Different between echo & print
|
print returns 1
echo supports echo "a", "b", "c"; |
|
PHP data types
|
String
Integer Float Boolean Array Object NULL |
|
3 ways top define int?
|
decimal: $x=10;
hexadecimal: $x=0x8c octal: $x=047; |
|
Define a PHP array
|
$cars=array("Volvo","BMW","Toyota");
|
|
What does var_dump do?
|
Dumps the variable data (like toString())
|
|
Does PHP support classes?
|
Yes, the class keyword works
|
|
Do PHP classes support constructors?
|
Yes
|
|
PHP sample class...
|
<?php
class Car { var $color; function Car($color="green") { $this->color = $color; } function what_color() { return $this->color; } } ?> |
|
How to get length of string?
|
strlen() function
|
|
How to get position of substring within string?
|
strpos() function
|
|
What does the define function do?
|
Defines constants in you code
define ( def, "defined" ); echo def; |
|
When accessing constants, do you use a $?
|
No.
define ( def, "defined" ); echo def; |
|
Difference between 'equal' and 'identical' operators?
|
Equal ==
True is equal Identical === True is equal and of same type |
|
What is the output of?
<?php $x=100; $y="100"; var_dump($x == $y); var_dump($x === $y); ?> |
True
False |
|
PHP else if...space or no space?
|
no space
|
|
PHP function keyword
|
function
|
|
2 ways to create array
|
$cars=array("Volvo","BMW","Toyota");
$cars[0]="Volvo"; $cars[1]="BMW"; $cars[2]="Toyota"; |
|
How to get length of array
|
$cars=array("Volvo","BMW","Toyota");
count($cars); sizeof($cars); NOTE: count and sizeof are identical. |
|
2 ways to define PHP maps
|
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
$age['Peter']="35"; $age['Ben']="37"; $age['Joe']="43"; |
|
sort arrays in ascending order
|
sort($cars);
|
|
sort arrays in descending order
|
rsort($cars);
|
|
sort associative arrays in ascending order, according to the value
|
asort()
|
|
sort associative arrays in ascending order, according to the key
|
ksort()
|
|
sort associative arrays in descending order, according to the value
|
arsort()
|
|
sort associative arrays in descending order, according to the key
|
krsort()
|
|
List PHP super-globals
|
$GLOBALS
$_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION |
|
$GLOBALS
|
$GLOBAL is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).
|
|
$_SERVERcount
|
$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
|
|
What is the output of...
echo $_SERVER['PHP_SELF']; echo $_SERVER['SERVER_NAME']; echo $_SERVER['HTTP_HOST']; echo $_SERVER['HTTP_REFERER']; echo $_SERVER['HTTP_USER_AGENT']; echo $_SERVER['SCRIPT_NAME']; |
/index.php
www.abc.com www.abc.com www.abc.com/index.php Mozilla 5.0... /index.php |
|
$_REQUEST
|
PHP $_REQUEST is used to collect data after submitting an HTML form.
|
|
$_POST
|
PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
|
|
$_GET
|
PHP $_GET can also be used to collect form data after submitting an HTML form with method="get".
|
|
In a HTML form, what is 'action' attribute?
|
The page path to send the form to
|
|
$_SERVER["PHP_SELF"]
|
The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script.
|
|
htmlspecialchars()
|
The htmlspecialchars() function converts special characters to HTML entities. This means that it will replace HTML characters like < and > with < and >. This prevents attackers from exploiting the code by injecting HTML or Javascript code (Cross-site Scripting attacks) in forms.
|
|
How to get the request method (GET/POST)?
|
$_SERVER["REQUEST_METHOD"]
|
|
How to check if a POST form element was passed or not?
|
empty()
if (empty($_POST["name"])) {$nameErr = "Name is required";} else {$name = test_input($_POST["name"]);} |
|
preg_match()
|
The preg_match() function searches a string for pattern, returning true if the pattern exists, and false otherwise.
|
|
isset()
|
Determine if a variable is set and is not NULL
|
|
What is output of...
<?php echo date("Y/m/d") . " "; echo date("Y.m.d") . " "; echo date("Y-m-d"); ?> |
2009/05/11
2009.05.11 2009-05-11 |
|
Difference between include and require
|
If resource is not found...
include > warning require > error |
|
Open a file
|
fopen()
$file=fopen("welcome.txt","r"); $file=fopen("welcome.txt","r") or exit("Unable to open file!"); |
|
Close a file
|
fclose($file);
|
|
What is a cookie?
|
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
|
|
Hoiw to create a cookie
|
setcookie()
Note: The setcookie() function must appear BEFORE the tag. |
|
How to access cookie data?
|
Use the $_COOKIE super global
echo $_COOKIE["user"]; |
|
How to delete a cookie?
|
Set the expiry time to past
setcookie("user", "", time()-3600); |
|
What is a session variable
|
A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
|
|
Session vs cookie
|
Both store user data between page loads
Cookie stored on client, session in server Sessions end when user closes browser, cookies end on expiry time |
|
DO you need to do anything before using session data?
|
Yes, start the session.
session_start(); ... session_destroy(); |
|
Hopw do sessions work?
|
Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.
|
|
Does PHP support email?
|
Yes.
The PHP mail() function is used to send emails from inside a script. |
|
set_exception_handler()
|
Sets a user-defined exception handler function
|
|
set_error_handler
|
This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions
|
|
Filter functions...
|
Used to validate and filter out invalid input data
|
|
Types of filter functions
|
filter_var() - Filters a single variable with a specified filter
filter_var_array() - Filter several variables with the same or different filters filter_input - Get one input variable and filter it filter_input_array - Get several input variables and filter them with the same or different filters |
|
AJAX Stands for
|
Asynchronous JavaScript and XML.
|
|
What is AJAX
|
AJAX is about updating parts of a web page, without reloading the whole page.
|
|
header()
|
Sends a raw HTTP header
|
|
How to send a redirect
|
Update the Location header in the response...
header('Location: http://www.example.com/'); |
|
headers_list()
|
headers_list() will return a list of headers to be sent to the browser / client. To determine whether or not these headers have been sent yet, use headers_sent().
|
|
headers_sent
|
Checks if or where headers have been sent.
You can't add any more header lines using the header() function once the header block has already been sent. |
|
How to set the page response code
|
http_response_code(404);
|
|
array_keys()
|
Gets the key set of a map.
|
|
What is COM
|
WINDOWS ONLY
Standard for allowing software component reuse. Implementation of COM object can be over network. COM object use the stand IDL interface. The essence of COM is a language-neutral way of implementing objects that can be used in environments different from the one in which they were created, even across machine boundaries. |
|
What is IDL?
|
Interface Definition Language.
IDL files DEFINE object-oriented classes, interfaces, structures, enumerations and other user-defined types in a language independent manner. |
|
All COM object implement the ??? interface.
|
IUnknown, containing...
QueryInterface() AddRef() Release() |
|
Discuss script execution time.
|
A PHP script is only allows to run for default 30sec (set in php.ini cfg file).
Your scrip can override this timeout using set_time_limit() set_time_limit(0) indicates inficite time limit. |
|
set_time_limit
|
Set the time limit for your scrip. Default 30sec.
|
|
strstr
|
Find the first occurrence of a string.
Aliased with strchr |
|
What are PHP extensions?
|
Bolt on library functionality needed explicit install.
|
|
4 ways to define a string
|
single quote ''
double quote "" heredoc nowdoc |
|
String defn: Single quotes
|
Used for simple strings.
Variables are not interlaced. Understands only a few escape characters |
|
String defn: Double quotes
|
More complex strings
Variables are interlaced Understands lots more escape chars |
|
String defn: heredoc
|
<<<
Useful for defining multiline strings. Interlaces $bar = <<< SOMETOKEN line 1 line2 line3 SOMETOKEN |
|
String def: Nowdoc
|
Similar to heredoc, but no interlacing
|
|
How do you append a string directly after an interlaced variable?
|
Use curly braces
echo "This square is {$width}cm broad."; |
|
explode()
|
Split a string by another string
|
|
needle
|
Needle in a haystack
Term used for string search functions |
|
Whats new in PHP 5?
|
Built-in native support for SQLite
improved MySQL support the object model was rewritten to allow for better performance and more features |
|
Can you call PHP functions statically?
|
Yes, use A::foo() notation.
Note. If called statically $this will not be defined. if (isset($this)) {} |
|
get_class()
|
Gets the name of the class of the given object.
|
|
Can a PHP class function be overriden by a derived class?
|
YES
|
|
Do PHP classes support member, method attributes public, protected, private?
|
YES
|
|
Do PHP classes support const members?
|
YES
|
|
func_num_args()
|
Gets the number of arguments passed to the function.
|
|
Do you need to specify function arguments in the function signature?
|
No.
You can pass args to functon foo(){}. You need to use func_num_args() and func_get_arg() to access them. |
|
func_get_arg()
|
Get the specified funciton argument (index)
|
|
func_get_args()
|
Gets array of function args
|
|
What is Joomla?
|
Open source CMS (content management system).
|
|
mysql_fetch_array
|
Gets a row from a query as a associative array (map).
|
|
Can PHP functions be overloaded?
|
NO
PHP function signatures used the name only, not the arg list. |
|
Difference between mysql_connect & mysql_pconnect
|
connect: create connection. Connection closed at end of script.
pconnect: find/create persistent connection. |
|
set_include_path()
|
Sets an include path.
When set you don't need to define you include file absolutely. |
|
Default size of upload files
|
2mb
|
|
user_error()
|
Alias for trigger_error
Generates a user-level error/warning/notice message |
|
PHP constructor
|
function __construct() {}
|
|
Do derived class constructor implicitly call base class constructors?
|
NO.
Use parent::__construct(); |
|
PHP destructor
|
function __destruct(){}
|
|
Do derived class destructors implicitly call base class constructors?
|
NO.
Use parent::__destruct(); |
|
Do PHP classes support static members?
|
YES
|
|
Difference between $this & self?
|
Use $this to refer to the current object.
Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members. |
|
DO PHP classes support abstract?
|
YES
Abstract classes cannot be instantiated. |
|
Can you create interfaces in PHP
|
YES. Use the interface keyword.
Classes use the implements keyword. |
|
PHP traits.
|
Like an interface but can come with a function implementation.
Enables concept of multiple inheritance. |
|
PHP Magic Methods
|
Class methods that are reserved, implemented by the 'base' object concept.
|
|
Does PHP support final class emthods?
|
YES
final functions cannot be overridden. |
|
PHP cloning
|
Like copy constructors, allowing you to implement your own deep copy.
Your class needs to implement maginc function __clone(). When cloning, use special operator. $a = clone $b; |
|
Explain PHP type hinting
|
In function args, you can define the class.
Acts like a cast to allow the object , inside the function, to be treated like the class. |
|
PHP serialisation
|
Allows you to serialize an object to string, and recreate from string.
serialize() unserialize() |