2. Language Basics Flashcards
What does Lexical Structure mean?
Set of basic rules that governs how you write in that language.
Which constructs are case-insensitive, and which are case-sensitive?
Case Insensitive – Classes & functions as well as built-in constructs and keywords.
Case Sensitive – Variables.
Is PHP Whitespace sensitive?
No, generally semi-colon is used for ends of lines and whitespace isn’t taken into account.
What are the multiple types of comments in PHP?
Single Line
- //
- #
Multi Line
- /* */
What are the legal identifiers for variables?
Must begin with a dollar sign, first character must be ASCII letter (upper or lower) or an underscore. After the first character, 0-9 are also valid characters.
Valid
$bill
$head_count
$I_HEART_PHP
$_secret
Invalid
$not valid
$*w
$3a
How do you define/use a constant?
Need to call the define(‘CONST_NAME’, ‘VALUE) function. Can be used from then on my referring to it by name.
What are Keywords in PHP?
Reserved words for the languages core functionality. They are case insensitive and can’t be used for variables/classes defined by the user.
What are the data types in PHP?
Scalar Types
- integer
- floating-point
- string
- boolean
Compound Types
- arrays
- objects
How do you define an Octal number in PHP?
Start an integer with a leading 0, and a series of digits 0-7.
How do you define a Hexadecimal value in PHP?
Prefix an integer with 0x followed by digits 0-9 or letters A-F.
How do you define a Binary value in PHP?
Write an integer value that begins with 0b followed by a sequence of 0-1.
What happens if you try to store a value that’s too big to hold an integer?
It will automatically convert to a floating-point value.
How can we test if a value is an integer?
Use the is_int() function.
Floating point values are only approximations, with that in mind how can we test if floats are equal?
Convert them to integers for comparison
How can you test if a value is a float?
Use the function is_float();
What’s the difference between single and double quoted strings in PHP?
Single quotes – String literals, they will not be interpolated.
Double quotes – Strings will be interpolated before returning value. (Variables will be expanded)
How can you test if two strings are equal?
Simply use == operator.
How can you test if a variable is a string in PHP?
Use the is_string() function
Booleans represent a truth value, what all values evaluate to false?
- keyword ‘false’
- integer 0
- floating-point 0.0
- empty string “” AND string “0”
- Empty array []
- the value NULL
How can we test if a value is a boolean?
use the is_bool() function
What are the 2 ways of creating an array in PHP?
using the array(“”) construct or the shorthand []
What are the 2 ways we can use a foreach loop with an array?
We can do foreach ($array as $value) OR foreach ($array as $index => $value) depending on if we need the index or not.
How can we determine if a variable is an array?
Use the is_array() function
How do we define a class?
Using the class keyword.
How do we create a new object from a class?
Use the new keyword. You can optionall pass parameters to the constructor if needed as well, or you can omit the parenthesis entirely.
How can you access the methods/properties of an object?
Use the -> (Arrow) construct.