diff --git a/_config.yml b/_config.yml index 6b9b0db..e13f69e 100644 --- a/_config.yml +++ b/_config.yml @@ -1,7 +1,4 @@ -auto: true safe: true -server: true -server_port: 4000 baseurl: / url: http://localhost:4000 diff --git a/_posts/01-02-01-Use-the-Current-Stable-Version.md b/_posts/01-02-01-Use-the-Current-Stable-Version.md index d8d5881..1edc3ec 100644 --- a/_posts/01-02-01-Use-the-Current-Stable-Version.md +++ b/_posts/01-02-01-Use-the-Current-Stable-Version.md @@ -5,7 +5,7 @@ isChild: true ## Use the Current Stable Version (5.5) {#use_the_current_stable_version_55_title} -If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.5][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.5 fool you, it represents _major_ improvements. If you are looking for a function or it's usage, the documentation on the [php.net][php-docs] website will have the answer. +If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.5][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.5 fool you, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. [php-release]: http://www.php.net/downloads.php [php-docs]: http://www.php.net/manual/en/ diff --git a/_posts/02-01-01-Code-Style-Guide.md b/_posts/02-01-01-Code-Style-Guide.md index 1cd16f9..3cd3fbb 100644 --- a/_posts/02-01-01-Code-Style-Guide.md +++ b/_posts/02-01-01-Code-Style-Guide.md @@ -24,7 +24,7 @@ You can use [PHP_CodeSniffer][phpcs] to check code against any one of these reco like [Sublime Text 2][st-cs] to be given real time feedback. Use Fabien Potencier's [PHP Coding Standards Fixer][phpcsfixer] to automatically modify your code syntax so that it -conforms with these standards, saving you from fixing each problem by hand. +conforms to these standards, saving you from fixing each problem by hand. English is preferred for all symbol names and code infrastructure. Comments may be written in any language easily readable by all current and future parties who may be working on the codebase. diff --git a/_posts/03-02-01-Programming-Paradigms.md b/_posts/03-02-01-Programming-Paradigms.md index eb0d567..2da54d9 100644 --- a/_posts/03-02-01-Programming-Paradigms.md +++ b/_posts/03-02-01-Programming-Paradigms.md @@ -18,7 +18,7 @@ interfaces, inheritance, constructors, cloning, exceptions, and more. ### Functional Programming -PHP supports first-class function, meaning that a function can be assigned to a variable. Both user defined and built-in +PHP supports first-class function, meaning that a function can be assigned to a variable. Both user-defined and built-in functions can be referenced by a variable and invoked dynamically. Functions can be passed as arguments to other functions (feature called Higher-order functions) and function can return other functions. @@ -39,7 +39,7 @@ can be used interchangeably with anonymous functions in almost all cases. ### Meta Programming -PHP supports various forms of meta programming through mechanisms like the Reflection API and Magic Methods. There are +PHP supports various forms of meta-programming through mechanisms like the Reflection API and Magic Methods. There are many Magic Methods available like `__get()`, `__set()`, `__clone()`, `__toString()`, `__invoke()`, etc. that allow developers to hook into class behavior. Ruby developers often say that PHP is lacking `method_missing`, but it is available as `__call()` and `__callStatic()`. diff --git a/_posts/03-05-01-Command-Line-Interface.md b/_posts/03-05-01-Command-Line-Interface.md index c323dc1..3cbaa16 100644 --- a/_posts/03-05-01-Command-Line-Interface.md +++ b/_posts/03-05-01-Command-Line-Interface.md @@ -4,7 +4,7 @@ isChild: true ## Command Line Interface {#command_line_interface_title} -PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrativia. +PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrivia. CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! @@ -32,7 +32,7 @@ echo "Hello, $name\n"; PHP sets up two special variables based on the arguments your script is run with. [`$argc`][argc] is an integer variable containing the argument *count* and [`$argv`][argv] is an array variable containing each argument's *value*. The first argument is always the name of your PHP script file, in this case `hello.php`. -The `exit()` expression is used with a non zero number to let the shell know that the command failed. Commonly used exit codes can be found [here][exit-codes] +The `exit()` expression is used with a non-zero number to let the shell know that the command failed. Commonly used exit codes can be found [here][exit-codes] To run our script, above, from the command line: diff --git a/_posts/04-03-01-PEAR.md b/_posts/04-03-01-PEAR.md index b48fa44..f5315a8 100644 --- a/_posts/04-03-01-PEAR.md +++ b/_posts/04-03-01-PEAR.md @@ -5,7 +5,7 @@ isChild: true ## PEAR {#pear_title} Another veteran package manager that many PHP developers enjoy is [PEAR][1]. It behaves much the same way as Composer, -but has some noteable differences. +but has some notable differences. PEAR requires each package to have a specific structure, which means that the author of the package must prepare it for usage with PEAR. Using a project which was not prepared to work with PEAR is not possible. @@ -19,8 +19,8 @@ if version conflicts between two projects arise. You can install PEAR by downloading the phar installer and executing it. The PEAR documentation has detailed [install instructions][2] for every operating system. -If you are using Linux, you can also have a look at your distribution package manager. Debian and Ubuntu for example -have a apt ``php-pear`` package. +If you are using Linux, you can also have a look at your distribution package manager. Debian and Ubuntu, for example, +have an apt ``php-pear`` package. ### How to install a package diff --git a/_posts/06-01-01-Databases.md b/_posts/06-01-01-Databases.md index ce47ec4..5f024fa 100644 --- a/_posts/06-01-01-Databases.md +++ b/_posts/06-01-01-Databases.md @@ -57,7 +57,7 @@ database preventing potential SQL injection attacks. You should also be aware that database connections use up resources and it was not unheard-of to have resources exhausted if connections were not implicitly closed, however this was more common in other languages. Using PDO you can implicitly close the connection by destroying the object by ensuring all remaining references to it are deleted, -ie. set to NULL. If you don't do this explicitly, PHP will automatically close the connection when your script ends +i.e. set to NULL. If you don't do this explicitly, PHP will automatically close the connection when your script ends - unless of course you are using persistent connections. * [Learn about PDO connections][5] diff --git a/_posts/07-01-01-Errors-and-Exceptions.md b/_posts/07-01-01-Errors-and-Exceptions.md new file mode 100644 index 0000000..f1b8566 --- /dev/null +++ b/_posts/07-01-01-Errors-and-Exceptions.md @@ -0,0 +1,6 @@ +--- +title: Errors and Exceptions +--- + +# Errors and Exceptions {#errors_and_exceptions_title} + diff --git a/_posts/07-02-01-Errors.md b/_posts/07-02-01-Errors.md new file mode 100644 index 0000000..dd4daeb --- /dev/null +++ b/_posts/07-02-01-Errors.md @@ -0,0 +1,11 @@ +--- +isChild: true +--- + +## Errors {#errors_title} + +PHP has several levels of error severity. The three most common types of messages are errors, notices and warnings. These have different levels of severity; `E_ERROR`, `E_NOTICE`, and `E_WARNING`. Errors are fatal run-time errors and are usually caused by faults in your code and need to be fixed as they'll cause PHP to stop executing. Warnings are non-fatal errors, execution of the script will not be halted. Notices are advisory messages caused by code that may or may not cause problems during the execution of the script, execution is not halted. + +Another type of error message reported at compile time is the `E_STRICT` message, these messages are used to suggest changes to your code to help ensure best interoperability and forward compatibility for your code. + +* [Predefined Constants for Error Handling](http://www.php.net/manual/en/errorfunc.constants.php) \ No newline at end of file diff --git a/_posts/05-05-01-Exceptions.md b/_posts/07-03-01-Exceptions.md similarity index 98% rename from _posts/05-05-01-Exceptions.md rename to _posts/07-03-01-Exceptions.md index 56311b6..f5d68c3 100644 --- a/_posts/05-05-01-Exceptions.md +++ b/_posts/07-03-01-Exceptions.md @@ -17,7 +17,7 @@ obvious. Another problem is when classes automatically throw an error to the screen and exit the process. When you do this you stop another developer from being able to dynamically handle that error. Exceptions should be thrown to make a developer aware -of an error, then they can choose how to handle this. E.g: +of an error; they then can choose how to handle this. E.g.: {% highlight php %} = 5.3.7. -Below we hash a string, we then check the hash against a new string. Because our two source strings are different ('secret-password' vs. 'bad-password') this login will fail. +Below we hash a string, and then check the hash against a new string. Because our two source strings are different ('secret-password' vs. 'bad-password') this login will fail. {% highlight php %} output = $outputType; + } + + public function loadOutput() + { + return $this->output->load(); + } +} +{% endhighlight %} + +The calling client class above has a private property which must be set at runtime and be of type 'OutputInterface' +once this property is set a call to loadOutput() will call the load() method in the concrete class of the output type +that has been set. +{% highlight php %} +setOutput(new ArrayOutput()); +$data = $client->loadOutput(); + +// Want some JSON? +$client->setOutput(new JsonStringOutput()); +$data = $client->loadOutput(); + +{% endhighlight %} + +* [Strategy pattern on Wikipedia](http://en.wikipedia.org/wiki/Strategy_pattern) + ## Front Controller The front controller pattern is where you have a single entrance point for you web application (e.g. index.php) that