H1 PHP basics

Syntax Anatomy of a PHP script Data types Variables Constants Operators Control structures Namespaces

H2 Functions

Basic Syntax Returning Values Variable Scope

H3 Strings and Patterns

Display an asterisk Variable interpolation Heredoc nowdoc syntax Escaping literal values Working with Strings Comparing, Searching and Replacing Strings Formatting Strings

H4 Array operations

H4 Array basics H4 Array operations H4 Array iteration H4 Sorting Arrays

H5 Web Programming

H5 Forms and urls

H6 Files, Streams, and Network Programming

H6.1 Reading files with file handles H6.2 Detecting end-of-file H6.3 Reading CSV files H6.4 Accessing network resources as files H6 Just some functions

H7 Database Programming

H8 Data Formats and Types

H8.1 JSON encoding/decoding H8.2 Dates and times H8.3 Extensible Markup Language H8.4 SimpleXML H8.5 DOM

H9 OO Programming in PHP

H9.1 OOP fundamentals H9.2 Class Methods and Properties H9.3 Constants, Statics en Props H9.4 Interfaces and Abstract classes

H10 Closures and Callbacks

H10.1 Closures H10.2 Callbacks

H11 Elements of OO Design

H11.1 Designing Codes H11.2 Design Pattern Theory H11.3 The Standard PHP Library H11.4 Generators

H12 Errors and Exceptions

Errors And Error management Exceptions

H13 Security

H14 Web Services

App A Array Functions

App B Filter Extension Filters and Flags

App C phpdbg

Chapter 1 PHP basics


Nothing to fiddle with in this paragraph...

Anatomy of a PHP script

Nothing to fiddle with in this paragraph...

Data types

Converting Between Data Types

Float's precision issue



Type Casting

Type has lots of unexpected (and incorrect) results, so we better get used to that.

Listing 1.2: Casting to an object

Casting to a boolean: any inputvalue other then 0, "0", "", or NULL is false

Expressions cast each value to the most important variabletype present.

Arrayvalues getting casted to an integer

Arraykeys getting casted to a boolean

Listing 1.3: Circumventing naming constraints

Listing 1.4: Using print_r

Using var_dump

Determining If a Variable Exists

Determining If a Variable Empty



Listing 1.6: defining constants



Listing 1.7: Incrementing/decrementing operators

Listing 1.8: Concatenate operators

Listing 1.9: Bitwise multiplication

The bitwise operators: ~ & | and ^

Assignment operators

Referencing variables, Assign by reference

Comparison operators

Binary operators AND OR XOR (logical operators)

Other operators

Binary operators &&, AND, ||, OR, XOR. (Operator precedence and Associativity)


Control Structures

Listing 1.10: If-then-else and Listing 1.11: Nested If-then-else

The ternary operator

Listing 1.12: Multiple matches for if-then-else AND Listing 1.13: Switch statement

Listing 1.15: While and Do loops



Listing 1.18: A namespaced class

Listing 1.19: A namespaced function

Listing 1.20: Accessing a namespaced function before 5.6

Listing 1.21: Falling back to global scope