Zend Flashcards
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
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 \
) - 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?
- 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.