• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/58

Click to flip

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;

58 Cards in this Set

  • Front
  • Back
What languages influence PHP syntax
Prdominantly C language, but influence from PERL. Recent object-orenented syntax from JAVA
What are the four types of PHP tags?
Standard <?php code ?>
Short <? code ?> & <?= $variable ?>
Script <script language="php"> code </script>
ASP <% code %>
What PHP tags should be used and why?
Standard <?php code ?>

Best solution for portablility and backwards compatiblity. Also, cannot be disabled in PHP config file.

Other tags are considered depreciated.
What character is used to terminate PHP statements?
;

This is not required for the last statement in the closing tag, but should be added for consistency.
How is a line commented? Multi-line commented?
Single line: // line
# line
Multi-line: /* line1
line2
*/
Where are three places where you CANNOT use whitespace characters?
- Between <? and php
- To break apart keywords (e.g whi le, funct ion>
)
- To break apart variable and function names (e.g. $var name, function foo bar)
What characters define a code block?
"{" and "}"
What is a language construct?
Elements pre-built into the language that follow special rules. The most common in PHP is the echo construct. It is not a function since is does not return a value.
What are the two general categories of PHP data types and their differences?
Scalar: Contain one value at a time
Composite: Containers of other data
What are the four scalar data types?
Boolean: Either true or false
int: signed numeric iteger value
float: signed floating-point value
string: collection of binary data
What are the three different notation of integers PHP supports?
Decimal: 10; -11; 1452: No thousand separator needed, or allowed
Octal: 0666; 0100: Identified by leading zero, used mainly to identify UNIX permisions
Hexadecmial: 0x123; 0XFF; -0x100: Base 16 notation, leading 0x that is case insensitive
What are the two different notations of floating-point numbers PHP supports?
Decimal: 0.12, 12.14, -.123: Traditional decimal notation
Exponential: 2E7, 1.2e2: a set of significant digits (also called mantissa), followed by the case-insensitive letter E and then by an exponent. The resulting number is expressed multiplied by 10 to the power of the exponent, for example, 1e2 equals 100.
Can the precision and range of numbers vary in PHP, and if so, why?
Yes. Depending on how PHP was complied, on a 64 bit platform, maybe capable of wider range then on 32 bit platform.
Does PHP track overflows?
No.
Consider the following statement:

echo (int) ((0.1 + 0.7) * 10)
What is printed out and why?
7. This is because prior to the int conversion, the number is stored as 7.999999 instead of 8. The int conversion chops the remander off. Because of this, you should consider using the BCMath exension instead of PHP built in data types
Many programmers consider strings equivilant to text. Is this the case in PHP? Why or why not?
This is not the case in PHP. Strings are considered binary data. Due to this, you could store text, image files, spreadsheet, music recordings, etc in string data types.
Describe data-type conversions for the following:
Number converted to a Boolean
String converted to a Boolean
Boolean converted to a number or string
A number to a boolean becomes false if the original value is zero, true otherwise
A string converted to a boolean is false if it is empty or equals "0". If it contains other data, even multiple zeros, it is true.
When boolean is converted to a number or string, 1 if true, 0 if false
What two compound data types are supported in PHP?
Array: Containers of ordered data elements that can contain other data types, event other arrays
Objects: Containers of both data and code. Form basis of Object Oriented programing
What two other data types, aside from Scaler and Compound are found in PHP?
NULL: indicates a variable has no value.
resource: used to indicate external resources that are not natively used by PHP, such as a file handle.
What is type conversion and how does a user force it in PHP?
Type conversion is converting from one data type to another. This is done by placing the type you want to convert to in brackets before the expression. Example:
$x = 10.88;
echo (int) $x; //outputs 10

Not that you cannot convert any value to a resource, but you can convert a resource to a value, resulting in the resource's ID number.
PHP variables are "loosely typed" while other languages are "strongly typed." What is the difference between the two?
Loosely typed: implicitly change the type of the variable as needed depending on the operation being performed on it's value

Strongly typed: variable can only contain one type of data throughout its existence.
What are the rules for naming variable in PHP?
Number, letters and underscore only allowed. Variable must start with underscore or letter.
What is a variable variable?
It is the process of taking the value of one variable and using it has the name of another variable using the "$$" syntax. Example:
$name = 'foo';
$$name = 'bar';
echo $foo; //Displays 'bar'

Due to this, it is possible to create variable names that do not follow PHP variable naming rules. Use extreme care since they can make code difficult to understand and improper use could lead to security issues.
Describe what the following code will do in PHP:

function myFunc() {
echo 'myFunc!';
}

$f = 'myFunc';
$f();
Setting $f to 'myFunc' and then executing the statement $f() will execute the function called 'myFunc', echoing out "myFunc!"
What does the function isset() do in PHP?

Example:
echo isset ($x);
Will return true if variable exists AND has a value other then NULL.
How do you define a constant in PHP?
Use the 'define' function:

define('EMAIL', 'somoneon@here.net');
echo EMAIL; //Display someone@here.net
What are the naming rules for constants in PHP?
They can contain only letters, numbers and underscores. They should be named in uppercase letters as in standard programing practices, but is not required.
What are the various operators used in PHP?
Assignment: assign data to variables
Arithmetic: perform basic math functions
String: join two or more strings
Comparision: compare two pieces of data
Logical: perform logical operations on boolean data

Bitwise: manipulating bits using boolean math
Error Control: suppressing errors
Execution: executing system commands
Incrementing/Decrementing: incrementing and decrementing numberical values
Type: identifying objects
What are the five arithmetic operators used in PHP?
Addition: $a = 1 +3.5;
Subtraction: $a = 4 - 2;
Multiplication: $a = 8 * 3:
Division: $a = 15 / 5;
Modulus: $a = 23 % 7;
How are incrementing and decrementing operators used in PHP? What are their symbols?
If the operator is placed after its operand, the interpreter will first return the value of the latter (unchanged), then then increment/decrement it by 1


If the operator is placed before the operand, the interpeter will first increment/decrement the value of the latter, and then return the newly calculated value.
Example:
$a = 1;
echo $a++ //Output 1, $a now equal to 2
echo ++$a; //Output 3, $a now equal to 3
echo --$a: //Output 2, $a now equal to 2
echo $a-- //Output 2, $a now equal to 1
How are strings concatenated in PHP?
Using the "." character.

Example: $var1 . $var2
What data type will bitwise operators only work on? What if they aren't that data type?
Integers. If the operands are not integers, the interpreter will attempt to convert them.
What are the six bitwise operators and how they are represented?
Not: ~
AND: &
OR: |
XOR: ^
Left Shift: <<
Right Shift: >>
How to the bitwise operators shift right/left work?
Shift Left: shifts bits left resulting in multiplication.
$x = 1;
echo $x << 1 // Outputs 2
echo $x << 2 // Outputs 4

Shift Right: shifts bits right resulting in division.
$x = 8;
echo $x >> 1 // Outputs 4
echo $x >> 2 // Outputs 2
Why must you be carefull when using the bitwise operators right/left shift?
It is possible to shift the bits out of the integer type that holds them, resulting in either overflow or underflow scenarios.
By default, assignment operators work by value. What does this mean?
When you assign a variable to another, its value is copied to the variable. Any change made to the copied value does not affect the original variable.
Describe how to assign variable by reference and what that means.
To pass a variable by reference, you use the "&" character.
Example:
$a = 10;
$b = &$a; //by reference
$b = 20;
echo $a; //Outputs 20

This works for all data types, except objects, which are always passed by reference.
In comparision operators, what are the four equivalence operations?
== Equivalence, true if both operands can be converted to a common datatype and are equal
=== Identity, true if only the datatypes are the same and the values are the same.
!= Not Equivalent, true if both operands are not equivalent, with out regards to data type
!== Not Identical, true if both operands are not of the same data type or do not have the same value
What comparision operators are used for greater/less then?
< and <=, less then; less then or equal to

> and >=, greater then, or greater then or equal to
What are the four logical operators used in PHP and their symbols?
NOT: "!" prior to operand: !$a
AND: "&&" or "and": $a and $b, $a && $b
OR: "||" or "or": $a || $b, $a or $b
Exclusive OR: "XOR": $a XOR $b
Out of the four logical operators, why is the NOT operator different?
The NOT "!" operator is urinary and works on one operand, while the other three are binary and work on two operands.
If the left-hand operand evaluates to false in an AND operation, is the right-hand side evaluated?
Not in PHP, if the left-hand side is false, the right-hand side is never evaluated.
What is the error suppression operator?
The "@" symbol is used for the error suppression operator. If it it prepends an expression, then it will prevent PHP from outputting an error, provided that the function uses PHP's own functionality to report errors.

Example:

$x = @mysql_connect();
How would you execute shell commands in PHP?
You can use the backtick operator to execute shell commands.

Example:

$a = `ls -l`;
What is operator associativity?
Associativity is the direction operations are performed on an operation. This can be left to right, right to left, or none.
What is a control structure?
They allow you to control the flow of a script. Examples of these are if statements, loops, etc.
What are conditional structures and examples there of?
Conditional structures are used to change the flow of a script based on one or more conditions.

Example:

if (expression){
}
elseif (expression){
}
else (expression){
}

10 == $x ? 'YES' : 'NO";

switch($a){
case true:
break;
default;
break
}
What ternary operator is used as a shortcut for if-then-else?
Example:

echo 10 == $x ? 'YES' : 'NO";

Same as:

if (10 == $x){
echo 'YES';
}
else{
echo 'NO';
}
Describe a switch construct?
An initial expression is evaluated once, then compared to individual case values. A break statement is required to break out of the statement, or cases below the match will continue to be executed.

Example:

$a = true;
switch($a){
case true:
echo "true";
break;
default;
echo "not true";
break
}
What is an iterative construct?
Iterative constructs make it possible to run the same portion of code multiple times. These are more commonly known as loops.
How many iterative constructs does PHP have and what are they?
Four, although only two are necessary to the functioning of the language.

while (condition){//code}
do{code}while(condition);
for(start instruction, condition, end loop instruction){//code};
foreach(array as value){//code}
How does the break keyword affect a loop?
When the break keywords is encountered in a loop, the loop will be exited at that point.
In the following code snippet, what does "break 2" mean:

for ($i = 0; $i < 10; $i++){
for ($j = 0; $j < 3; $j++){
if (($j+ $i) % 5 == 0){
break 2;
}
}
}
Adding a number after the break keyword tells the interpreter how many nested loops to break out of. In this example, "break 2" will break out of both loops.
Why should you always remember to end the "break" statement with a semi-colon?
If the break statement does not end with a semi-colon, and the code right after returns an integer, then this is appended to the break statement, possibly breaking out of multiple loops when not intended to.

Example;

$a = 1;
break
$a + 1;

would equivalate to break 2;
What does the "continue" keyword do in a loop?
The continue keyword will stop the rest of the code from executing in the loop, and start a new iteration of the loop.

Example:

while(true){
echo "hello";
continue;
echo "there";
}

"hello" will be echoed forever, but "there" will never be echoed.
What are the five error levels in PHP?
Compile-time errors: Errors detected by the parser while it is compiling a script. Cannot be trapped in the script itself.

Fatal errors: Errors that halt the execution of a script. Cannot be trapped.

Recoverable errors: Errors that represent significant failures, but can still be handled in a safe way.

Warnings: Recoverable errors that indicate a run-time fault. Do not halt the execution of a script.

Notices: Indicate that an error condition occurred, but is not necessarily significant. Do not halt the execution of a script.
By default, PHP reports errors it encounters to the scripts output. Why is this bad in a production environment and how can it be turned off?
Displaying all errors to users in a production environment is bad form, and a possible security issue. To disable errors from being displayed, in the php.ini add/edit the following line to the following:

display_errors = Off
What function can be used to set your own error handler in PHP?
set_error_handler(error_function,error_types)

<?php
//error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
echo "Ending Script";
die();
}

//set error handler
set_error_handler("customError");

$test=2;

//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>