PHP


  1. http://git.php.net/?p=php-src.git&a=summary
  2. https://github.com/php/php-src
  3. https://wiki.php.net/vcs/gitworkflow
  4. https://www.php.net/manual/en/doc.changelog.php
  5. https://www.php.net/supported-versions.php
  6. https://eev.ee/blog/2012/04/09[...]actal-of-bad-design/
  7. http://www.phptherightway.com/
  8. http://www.phpthewrongway.com/

-> /Dev/Guidelines/CodeConventions

1. Quotes

Understand the difference between single and double quotes. Use whichever is more appropriate.

2. Indentation

Indentation should follow the logical structure of the code. Use real tabs not spaces.

3. Difference between isset empty is_null


Comparison Table


TEST Not Set NULL Zero FALSE Numeric Value Empty String
isset() bool(false) bool(false) bool(true) bool(true) bool(true) bool(true)
empty() bool(true) bool(true) bool(true) bool(true) bool(false) bool(true)
is_null() bool(true) bool(true) bool(false) bool(false) bool(false) bool(false)
== bool(true) bool(true) bool(true) bool(true) bool(false) bool(true)
=== bool(false) bool(false) bool(false) bool(true) bool(false) bool(false)

https://www.php.net/manual/de/types.comparisons.php

3.1. isset($vars[1]) AND !empty($vars[1])

empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.

Use simply !empty($vars[1]) here.


if ($vars === [])

4. List of Parser Tokens

https://www.php.net/manual/en/tokens.php

5. Pattern Modifiers

Second only to memory, pattern recognition is the most powerful cognitive ability that we have. Without it, we could not learn, we could not extrapolate, we could not infer, we could not discover—we could not grow.

Pattern recognition rules.


So don't deny it — embrace it.

Special Sequences

    \w - Any “word” character (a-z 0-9 _)
    \W - Any non “word” character
    \s - Whitespace (space, tab CRLF)
    \S - Any non whitepsace character
    \d - Digits (0-9)
    \D - Any non digit character
    . - (Period) – Any character except newline

Meta Characters

    ^ - Start of subject (or line in multiline mode)
    $ - End of subject (or line in multiline mode)
    [ - Start character class definition
    ] - End character class definition
    | - Alternates, eg (a|b) matches a or b
    ( - Start subpattern
    ) - End subpattern
    \ - Escape character

Quantifiers

    n* - Zero or more of n
    n+ - One or more of n
    n ? - Zero or one occurrences of n
    {n} - n occurrences exactly
    {n,} - At least n occurrences
    {,m} - At most m occurrences
    {n,m} - Between n and m occurrences (inclusive)

Pattern Modifiers

    i - Case Insensitive
    m - Multiline mode - ^ and $ match start and end of lines
    s - Dotall - . class includes newline
    x - Extended– comments and whitespace
    e - preg_replace only – enables evaluation of replacement as PHP code
    S - Extra analysis of pattern
    U - Pattern is ungreedy
    u - Pattern is treated as UTF-8

Point based assertions

    \b - Word boundary
    \B - Not a word boundary
    \A - Start of subject
    \Z - End of subject or newline at end
    \z - End of subject
    \G - First matching position in subject

Assertions

    (?=) - Positive look ahead assertion foo(?=bar) matches foo when followed by bar
    (?!) - Negative look ahead assertion foo(?!bar) matches foo when not followed by bar
    (?<=) - Positive look behind assertion (?<=foo)bar matches bar when preceded by foo
    (? - Negative look behind assertion (?
    (?>) - Once-only subpatterns (?>\d+)bar Performance enhancing when bar not present
    (?(x)) - Conditional subpatterns
    (?(3)foo|fu)bar - Matches foo if 3rd subpattern has matched, fu if not
    (?#) - Comment (?# Pattern does x y or z)	

http://www.pcre.org/pcre.txt
PCRE2 Syntax
PCRE Pattern Modifiers
PCRE Pattern Syntax


Play and Test

  1. https://regex101.com/ - Online regex tester and debugger

6. Online services