IteratorAggregate

The IteratorAggregate is an interface to create an external Iterator.

While Iterator is an interface for external iterators or objects that can be iterated themselves internally.

IteratorAggregate is an easy way to implement an Iterator. The disadvantage is you cannot add next(), key(), etc methods, as they won’t get called during a normal foreach traversal.

If you need to implement custom methods, you need to implement an OuterIterator or (easier) to extend an IteratorIterator.

Share

Pattern Modifier

The current possible PCRE modifiers are listed below. The names in parentheses refer to internal PCRE names for these modifiers. Spaces and newlines are ignored in modifiers, other characters cause error.

i (PCRE_CASELESS)
m (PCRE_MULTILINE)
s (PCRE_DOTALL)
x (PCRE_EXTENDED)
e (PREG_REPLACE_EVAL)
A (PCRE_ANCHORED)
D (PCRE_DOLLAR_ENDONLY)
S
U (PCRE_UNGREEDY)
X (PCRE_EXTRA)
J (PCRE_INFO_JCHANGED)
u (PCRE_UTF8)

Share

stream_copy_to_stream()

int stream_copy_to_stream ( resource source, resource dest [, int maxlength [, int offset]] )

Makes a copy of up to maxlength bytes of data from the current position (or from the offset position, if specified) in source to dest. If maxlength is not specified, all remaining content in source will be copied.

stream_copy_to_stream($source_file, $destination_file);

Share

Superglobals

Several predefined variables in PHP are “superglobals”, which means that they are always accessible, regardless of scope – and you can access them from any function, class or file without having to do anything special.

The PHP superglobal variables are:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION

$_SESSION superglobals does not necessarily contain data from the client

Share

password_hash()

password_hash() creates a new password hash using a strong one-way hashing algorithm. password_hash() is compatible with crypt(). Therefore, password hashes created by crypt() can be used with password_hash().

To hash a password, take the password string and pass it into password_hash the function as a parameter along with the algorithm you want to use, then store the returned hash into the database.

Following are the acceptable ways to create a secure password hash in PHP

A. crypt()
B. hash_pbkdf2()
C. password_hash()

Share

Static Binding

Late Static Binding is something that helps us correctly resolve to static classes at run time. So when we use self keyword, PHP checks it at compile time which class to bind the method call to but when we use static keyword, PHP would check it late eg it would determine which class to use and bind method call to at runtime. Doing it at runtime is what helps PHP determine which class was meant.

Late static binding is used in PHP to use caller class information provided in static method call.

Share