• 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/142

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;

142 Cards in this Set

  • Front
  • Back
Why doesn't the concept of "void" apply in PHP functions?
PHP functions always return a value, even if it's not specified.
What does a function return if no return value is set?
NULL
How do you return by reference?
function &functionName()'
How do you return an expression by reference?
You can't, only variables can be returned by reference.
By default how will an object be returned?
By reference
What is a common reason to return by reference?
For resources, like database connections.
What happens if you don't return a variable in a function that returns by reference?
You get an error.
What are the three variable scopes?
Global, Function and Class
How can you access a variable with function scope once the function is no longer available?
You can't
How can you access global variables inside a function
1. Importing with 'global $a;' or 2. use the superglobal array $GLOBALS['a'];
What's an efficient way to access multiple global variables inside a function
Importing with a comma separated list of variables.
Why do developers prefer the superglobal array over importing?
It adds confusion to the code and $GLOBALS contains everything you would need.
What will happen if you pass more arguments to a function than were defined in the declaration?
Nothing, PHP doesn't care.
What will happen if you pass fewer arguments to a function than were defined in the declaration
PHP throws an error.
How can you give an argument a default value of an expression?
You can't
Where should argument's with default values be?
The rightmost positions in the list
What can you specify for type-hints?
Any class or interface name, array, or callable
How do you type-hint an argument?
Prepend the argument with the type.
Can you type-hint with a default value?
Yes, but the default value must be null.
What happens if you pass an invalid value into a type-hinted argument with a default value?
PHP throws an error.
How do you pass an argument by reference?
function functionName(&$arg1);
How do you pass an expression as a by-reference argument?
You can't, only variables can be passed by reference.
Can you set a default value for a by-reference argument?
Yes, but only in PHP 5+
What happens to a variable that is created by a default by-reference argument?
It is destroyed upon return.
What does func_get_args() do?
Returns an array of arguments passed to your function
What does func_num_args() do?
Returns the number of arguments passed to your function
What does func_get_arg() do?
Returns the argument value when you input the argument's position.
How do you declare a variadics?
function functionName($arg1, ...$args)'
Where can you declare a variadics?
Only the leftmost argument.
What is a variadics?
Allow you to explicitly denote a function as accepting a variable length of arguments; no longer having to manually retrieve arguments and separate them from named arguments
In function myFunction(...$args) how do I access each argument?
foreach ($args as $arg)
How do you pass variadics by reference?
function myFunction(&...$args)
How do you type-hint variadics?
function myFunction(Type ...$args)
What is 'unpacking'?
Passing an array-like data structure into an argument list?
How would you use unpacking in str_replace?
$args = ["v1", "v2", "v3"]; str_replace(...$args);
A string in single quotes represents what?
Simple Strings, almost all characters are used literally.
A string in double quotes represents what?
Complex Strings, allow for special escape sequences and variable substitutions.
What is the format of an escape sequence?
A backslash followed by one or more characters.
What syntax can you use to interpolate a variable in a string that cannot be readily parsed?
Wrap the variable in braces. "Hello {$name[1]}"
What is a heredoc?
A syntax to declare complex strings that can easily incorporated double quotes.
What is the heredoc syntax?
<
What is the difference between nowdoc and heredoc?
Nowdoc does not interpolate or use escape sequences.
What is the naming convention of heredoc identifiers?
Upper Case
What is the nowdoc syntax?
<<<'KEYWORD'...(newline)KEYWORD;
Can you use heredoc when defining a class property?
Only after PHP 5.3 and as of 5.6 you still can't interpolate.
Can you use nowdoc when defining a class property?
Yes, after PHP 5.3
How do you typically escape characters in a string?
Prepend character with a backslash
How can you escape a brace?
You can't, If you need a literal '{$', escape the dollar sign instead.
What data can PHP strings store?
Any data.
What data can PHP string functions work on?
Single byte characters only?
How can you work on multibyte strings?
With iconv and mbstring extensions
What is the default_charset?
UTF-8 (PHP 5.6+)
What does strlen() do?
It counts the number of bytes in a string.
What does binary-safe mean?
All Characters in the string are counted, regardless of value.
What does strtr() do?
Translates certain characters of a string into other characters. (Transliteration)
What is strtr() often used for?
To transform certain accented characters that cannot appear in URLs or email addresses into equivalent unaccented versions.
How can you use a string as an array?
Just use it the same way you would use an array.
What would echo "abcdef"[1] output?
b (PHP5.5+)
What is a zero-based index?
Index that starts at 0
When should you use the identity operator on strings?
Whenever you are performing a comparison that could lead to type-juggling problems?
What is the difference between strcmp() and strcasecmp()
strcasecmp() is case-sensitive
What does strcmp() do?
Compares two strings and returns zero if they are equal.
What does the optional 3rd parameter of strcasecmp() do?
It allows you to test a given number of characters only.
What does substr_compare() do?
It allows you to perform a comparison between two portions of strings.
What are the simplest and fastest string search functions?
strstr() and strpos()
What does strpos() do?
Returns the first position of the "needle" in a "haystack" or false if not found.
Why should you use identity, not equivalence operator with strpos()?
If the needle is in position 0, the equivalence operator would interpret it as false.
What does strpos() optional third parameter do?
It indicates the starting position of the haystack.
What does strstr() do?
Returns the part of the haystack that begins with the needle.
What is the fastest string function?
strstr()
Does strstr() have an optional third parameter?
No
What are the case-insensitive versions of strpos and strstr?
stripos(), stristr()
What is the reverse search version of strpos?
strrpos()
What does strspn() do?
It matches against a whitelist of allowed characters and returns the length of the first segment that contains said characters.
What does strcspn() do?
It matches against a blacklist of disallowed characters and returns the length of the first segment of string that don't have said characters.
What do $c and $d do in strspn($a, $b, $c, $d)?
$c sets the starting point and $d sets the length of string to examine.
What do $a, $b, $c and $d do in str_replace($a, $b, $c, $d)
$a is the needle, $b is the replacement string, $c is the haystack, $d is an optional by-reference variable that is filled with the number of substitutions made.
What is str_ireplace()?
Case-insensitive version of str_replace()
How would you search and replace more than one needle at a time?
Use arrays for needle and replacement string.
What do $a, $b, $c and $d do in substr_replace($a, $b, $c, $d)
$a is the input string, $b is the replacement string, $c indicates the starting point, $d is the optional end point.
What do $a, $b, and $c do in substr($a, $b, $c)?
$a is the input string, $b is the starting index, $c is the optional length of the substring.
How can you start counting from the end of a string in substr()?
Set the starting index to a negative number
What does setlocale() do?
It sets the location based on the locale and category you input. It affects formatting functions.
What does number_format do?
It separates digits into thousands, it is not locale-aware.
What do $a, $b, $c and $d do in number_format($a, $b, $c, $d)?
$a is the number, $b is number of decimals to round to (0 by default), $c will be the optional decimal separator, $d will be the optional thousands separator. $c and $d must be used together.
What currency will money_format() use?
It depends on your locale.
What do $a and $b do in money_format($a, $b)?
$a is a string, starting with '%', that crafts the format. $b is the number to be formatted.
Why should you reset your locale after using setlocale()?
It affects the whole script and different locales can have different rounding rules.
What do the printf() family of functions do?
They take an input string that specifies the output format and one or more values to return.
What character is the formatting specifier?
%
How can you escape the formatting specifier?
%%
Describe a sign specifier
A plus or minus symbol that determines how signed numbers are rendered.
Describe a padding specifier
Indicates what character should be used to make up the required output length if the input is not long enough
Describe an alignment specifier
Indicates if the output should be right or left aligned
Describe a numeric width specifier
Indicates the minimum length of the output
Describe a precision specifier
Indicates how many decimal digits should be displayed for floating points.
Describe type specifier '%b'
Output an integer as a binary number.
Describe type specifier '%c'
Output the character which has the input integer as its ASCII value.
Describe type specifier '%d'
Output a signed decimal number
Describe type specifier '%e'
Output a number using scientific notation (e.g., 3.8e+9)
Describe type specifier '%u'
Output an unsigned decimal number
Describe type specifier '%f'
Output a locale aware float number
Describe type specifier '%F'
Output a non-locale aware float number
Describe type specifier '%o'
Output a number using its Octal representation
Describe type specifier '%s'
Output a string
Describe type specifier '%x'
Output a number as hexadecimal with lowercase letters
Describe type specifier '%X'
Output a number as hexadecimal with uppercase letters
What does sscanf() do?
Accepts and parses formatted input.
What do $a and $b do in sscanf($a, $b)
$a is the input string, $b is the formatting pattern.
What should be true when you use sscanf()
The input data should follow a well-defined format, otherwise you can lose data.
What does PCRE mean?
Perl Compatible Regular Expressions.
What's one drawback of using regex search and replace?
It's much more computationally intensive than simple search and replace.
What is the conventional PHP Regex delimiter?
A Forward Slash
What does the metacharacter . do?
Match any character
What does the metacharacter ^ do?
Match the start of the string
What does the metacharacter $ do?
Match the end of the string
What does the metacharacter \s do?
Match any whitespace character
What does the metacharacter \d do?
Match any digit
What does the metacharacter \w do?
Match any “word” character
What does the quantifier * do?
The character can appear zero or more times
What does the quantifier + do?
The character can appear one or more times
What does the quantifier ? do?
The character can appear zero or one times
What does the quantifier {n,m} do?
The character can appear at least n times, and no more than m. Either parameter can be omitted to indicate a minimum limit with no maximum, or a maximum limit without a minimum, but not both.
How can you make a quantifier greedy?
They are greedy by default.
How can you make a quantifier un-greedy?
Append '?' to the quantifier.
How can you change the behavior of a Regex?
Add a pattern modifier after the closing delimiter.
What does the pattern modifier i do?
Makes pattern case-insensitive
What does the pattern modifier m do?
Indicates a multiline string. ^ and $ will match beginning and end of each line respectively.
What does the pattern modifier s do?
The 'any' character will also match newlines.
What does the pattern modifier x do?
Will ignore whitespace, newlines, characters after # and before newline.
What does the pattern modifier e do?
The 'eval' modifier lets you replace Regex with PHP expression. (Deprecated PHP 5.5)
What does the pattern modifier U do?
Makes quantifiers un-greedy by default.
What does the pattern modifier u do?
Treats pattern and subject as UTF-8. So it matches Characters instead of bytes.
What is a sub-expression?
Regex inside Regex. Defined by parenthesis.
What does preg_match($a, $b, $c) do?
Uses Regex $a to match agains $b. Return 1 if successful and if $c is included, returns all captured subpatterns.
How do you ad parentheticals to a subpattern?
(pattern)
What does preg_match_all() do?
Allows you to perform multiple matches on a string with a single Regex.
What does PREG_PATTERN_ORDER do in preg_match_all's third parameter?
Default behavior, each match is an array whose first array index is the entire matched string and each subsequent index is a capture group.
What does PREG_SET_ORDER do in preg_match_all's third parameter?
All matches for first capture group goes in first key, second goes in second key, etc. Good for named capture groups.
What does PREG_OFFSET_CAPTURE do in preg_match_all's third parameter?
Each matching string in the result is an array with the string itself and its offset from the beginning of the string.
What does preg_replace($a, $b, $c) do?
$a is the Regex pattern to match, $b is the replacement value (Can use captured subpatterns), $c is the string to search and replace.
What's the benefit of $c being an array in preg_replace($a, $b, $c)?
If you have multiple subjects to search and replace, it speeds things up as the regex only needs to be compiled once.