Merge branch 'gh-pages' of github.com:codeguy/php-the-right-way into gh-pages

This commit is contained in:
Josh Lockhart
2015-01-27 14:53:04 -05:00
33 changed files with 215 additions and 132 deletions

View File

@@ -62,7 +62,7 @@ included in the project:
git checkout -b <topic-branch-name>
```
4. Install the [Jekyll](https://github.com/mojombo/jekyll/) gem to preview locally.
4. Install the [Jekyll](https://github.com/jekyll/jekyll/) gem to preview locally.
5. Commit your changes in logical chunks. Please adhere to these [git commit
message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

View File

@@ -36,6 +36,7 @@ developers know where to find good information!
* [English](http://www.phptherightway.com)
* [Bulgarian](http://bg.phptherightway.com)
* [Chinese (Simplified)](http://wulijun.github.com/php-the-right-way)
* [Chinese (Traditional)](http://laravel-taiwan.github.io/php-the-right-way)
* [French](http://eilgin.github.io/php-the-right-way/)
* [German](http://rwetzlmayr.github.io/php-the-right-way)
* [Indonesian](http://id.phptherightway.com)
@@ -58,11 +59,13 @@ If you are interested in translating _PHP: The Right Way_, fork this repo on Git
To avoid fragmentation and reader confusion, please choose one of these options:
1. We link to your GitHub Pages fork with `[username].github.com/php-the-right-way`
1. We link to your GitHub Pages fork with `[username].github.io/php-the-right-way`
2. We link to your GitHub Pages fork with a subdomain (e.g. "ru.phptherightway.com")
If you use a subdomain, enter the subdomain into the `CNAME` file, and ask us to setup DNS for you. If you do not use a subdomain, remove the `CNAME` file entirely else your fork will not build when pushed.
Add information about your translation in the [wiki page](https://github.com/codeguy/php-the-right-way/wiki/Translations).
When your translation is ready, open an issue on the Issue Tracker to let us know.
## Why

View File

@@ -1,7 +1,4 @@
safe: true
baseurl: /
url: http://localhost:4000
highlighter: pygments
markdown: kramdown
permalink: date
@@ -11,3 +8,15 @@ maruku:
png_engine: blahtex
png_dir: images/latex
png_url: /images/latex
gems:
- jekyll-sitemap
defaults:
-
scope:
path: ""
values:
sitemap: false
exclude: ['CNAME', 'CONTRIBUTING.md', 'LICENSE', 'README.md', 'pages/example.md']

View File

@@ -18,11 +18,12 @@ and examples as they become available.
## Translations
_PHP: The Right Way_ is (or soon will be) translated into many different languages:
_PHP: The Right Way_ is translated into many different languages:
* [English](http://www.phptherightway.com)
* [Bulgarian](http://bg.phptherightway.com/)
* [Chinese (Simplified)](http://wulijun.github.com/php-the-right-way)
* [Chinese (Traditional)](http://laravel-taiwan.github.io/php-the-right-way)
* [French](http://eilgin.github.io/php-the-right-way/)
* [German](http://rwetzlmayr.github.io/php-the-right-way/)
* [Indonesian](http://id.phptherightway.com/)

View File

@@ -12,7 +12,7 @@
<meta property="og:site_name" content="PHP: The Right Way"/>
<meta property="og:type" content="website"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href='http://fonts.googleapis.com/css?family=Alfa+Slab+One|Droid+Serif:400,700' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Alfa+Slab+One|Droid+Serif:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{ site.baseurl }}styles/all.css"/>
<link rel="stylesheet" href="{{ site.baseurl }}styles/print.css" media="print, handheld"/>
<link rel="stylesheet" href="{{ site.baseurl }}styles/syntax.css"/>
@@ -95,14 +95,14 @@
<li><a href="http://www.newmediacampaigns.com">New Media Campaigns</a></li>
</ul>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">PHP: The Right Way</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.twitter.com/codeguy" property="cc:attributionName" rel="cc:attributionURL">Josh Lockhart</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://www.phptherightway.com" rel="dct:source">www.phptherightway.com</a>.
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="//i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">PHP: The Right Way</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.twitter.com/codeguy" property="cc:attributionName" rel="cc:attributionURL">Josh Lockhart</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://www.phptherightway.com" rel="dct:source">www.phptherightway.com</a>.
</p>
</footer>
</div>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="/scripts/setup.js"></script>
</body>
</html>

View File

@@ -12,7 +12,7 @@
<meta property="og:site_name" content="PHP: The Right Way"/>
<meta property="og:type" content="website"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href='http://fonts.googleapis.com/css?family=Alfa+Slab+One|Droid+Serif:400,700' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Alfa+Slab+One|Droid+Serif:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{ site.baseurl }}styles/all.css"/>
<link rel="stylesheet" href="{{ site.baseurl }}styles/syntax.css"/>
<link rel="icon" href="{{ site.baseurl }}images/favicon.png" type="image/png"/>
@@ -42,7 +42,7 @@
<a href="/">Return to Main Page</a>
<footer class="site-footer" id="site-footer">
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">PHP: The Right Way</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.twitter.com/codeguy" property="cc:attributionName" rel="cc:attributionURL">Josh Lockhart</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://www.phptherightway.com" rel="dct:source">www.phptherightway.com</a>.
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="//i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text" property="dct:title" rel="dct:type">PHP: The Right Way</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.twitter.com/codeguy" property="cc:attributionName" rel="cc:attributionURL">Josh Lockhart</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://www.phptherightway.com" rel="dct:source">www.phptherightway.com</a>.
</p>
</footer>
</div>

View File

@@ -18,6 +18,26 @@ There are multiple ways to install PHP on OS X.
At this point, you can install `php53`, `php54`, `php55` or `php56` using the `brew install` command, and switch
between them by modifying your `PATH` variable.
### Install PHP via Macports
The [MacPorts] Project is an open-source community initiative to design an
easy-to-use system for compiling, installing, and upgrading either
command-line, X11 or Aqua based open-source software on the OS X operating
system.
MacPorts supports pre-compiled binaries, so you don't need to recompile every
dependencies from the source tarball files, it saves your life if you don't
have any package installed on your system.
At this point, you can install `php53`, `php54`, `php55` or `php56` using the `port install` command, for example:
sudo port install php54
sudo port install php55
And you can run `select` command to switch your active php:
sudo port select --set php php55
### Install PHP via phpbrew
[phpbrew] is a tool for installing and managing multiple PHP versions. This can be really useful if two different
@@ -38,6 +58,7 @@ you and tie them all together, but ease of setup comes with a trade-off of flexi
[Homebrew]: http://brew.sh/
[Homebrew PHP]: https://github.com/Homebrew/homebrew-php#installation
[MacPorts]: https://www.macports.org/install.php
[phpbrew]: https://github.com/phpbrew/phpbrew
[mac-compile]: http://php.net/install.macosx.compile
[xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer

View File

@@ -10,7 +10,7 @@ could use a '.msi' installer. The installer is no longer supported and stops at
For learning and local development you can use the built in webserver with PHP 5.4+ so you don't need to worry about
configuring it. If you would like an "all-in-one" which includes a full-blown webserver and MySQL too then tools such
as the [Web Platform Installer][wpi], [Zend Server CE][zsce], [XAMPP][xampp], [EasyPHP][easyphp] and [WAMP][wamp] will
as the [Web Platform Installer][wpi], [XAMPP][xampp], [EasyPHP][easyphp] and [WAMP][wamp] will
help get a Windows development environment up and running fast. That said, these tools will be a little different from
production so be careful of environment differences if you are working on Windows and deploying to Linux.
@@ -22,7 +22,6 @@ there is a [dedicated area on iis.net][php-iis] for PHP.
[php-downloads]: http://windows.php.net
[wpi]: http://www.microsoft.com/web/downloads/platform.aspx
[zsce]: http://www.zend.com/en/products/server-ce/
[xampp]: http://www.apachefriends.org/en/xampp.html
[easyphp]: http://www.easyphp.org/
[wamp]: http://www.wampserver.com/en/

View File

@@ -21,10 +21,10 @@ interfaces, inheritance, constructors, cloning, exceptions, and more.
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.
other functions (a feature called _Higher-order Functions_) and function can return other functions.
Recursion, a feature that allows a function to call itself, is supported by the language, but most of the PHP code
focus on iteration.
Recursion, a feature that allows a function to call itself, is supported by the language, but most PHP code
is focused on iteration.
New anonymous functions (with support for closures) are present since PHP 5.3 (2009).

View File

@@ -16,11 +16,11 @@ two PHP classes with the same name may co-exist in separate PHP namespaces. It's
It is important for you to namespace your code so that it may be used by other developers without fear of colliding
with other libraries.
One recommended way to use namespaces is outlined in [PSR-0][psr0], which aims to provide a standard file, class and
One recommended way to use namespaces is outlined in [PSR-4][psr4], which aims to provide a standard file, class and
namespace convention to allow plug-and-play code.
In December 2013 the PHP-FIG created a new autoloading standard: [PSR-4][psr4], which one day will probably replace
PSR-0. Currently both are still usable, as PSR-4 requires PHP 5.3 and many PHP 5.2-only projects currently implement
In October 2014 the PHP-FIG deprecated the previous autoloading standard: [PSR-0][psr0], which has been replaced with
[PSR-4][psr4]. Currently both are still usable, as PSR-4 requires PHP 5.3 and many PHP 5.2-only projects currently implement
PSR-0. If you're going to use an autoloader standard for a new application or package then you almost certainly want
to look into PSR-4.

View File

@@ -11,6 +11,8 @@ primarily of commonly needed datastructure classes (stack, queue, heap, and so o
over these datastructures or your own classes which implement SPL interfaces.
* [Read about the SPL][spl]
* [SPL video course on Lynda.com(Paid)][spllynda]
[spl]: http://php.net/book.spl
[spllynda]: http://www.lynda.com/PHP-tutorials/Up-Running-Standard-PHP-Library/175038-2.html

View File

@@ -6,10 +6,10 @@ anchor: command_line_interface
## Command Line Interface {#command_line_interface_title}
PHP was created to write web applications, but is also useful for scripting command line interface (CLI) programs.
Command line PHP programs can help automate common tasks like testing, deployment, and application administrivia.
Command line PHP programs can help automate common tasks like testing, deployment, and application administration.
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!
GUI for it. Just be sure **not** to put your CLI PHP scripts in your public web root!
Try running PHP from your command line:
@@ -26,7 +26,7 @@ Let's write a simple "Hello, $name" CLI program. To try it out, create a file na
{% highlight php %}
<?php
if ($argc != 2) {
if ($argc !== 2) {
echo "Usage: php hello.php [name].\n";
exit(1);
}

View File

@@ -1,20 +1,20 @@
---
title: XDebug
title: Xdebug
isChild: true
anchor: xdebug
---
## XDebug {#xdebug_title}
## Xdebug {#xdebug_title}
One of the most useful tools in software development is a proper debugger. It allows you to trace the execution of your
code and monitor the contents of the stack. XDebug, PHP's debugger, can be utilized by various IDEs to provide
code and monitor the contents of the stack. Xdebug, PHP's debugger, can be utilized by various IDEs to provide
Breakpoints and stack inspection. It can also allow tools like PHPUnit and KCacheGrind to perform code coverage
analysis and code profiling.
If you find yourself in a bind, willing to resort to `var_dump()`/`print_r()`, and you still can't find the solution -
maybe you need to use the debugger.
[Installing XDebug][xdebug-install] can be tricky, but one of its most important features is "Remote Debugging" - if
[Installing Xdebug][xdebug-install] can be tricky, but one of its most important features is "Remote Debugging" - if
you develop code locally and then test it inside a VM or on another server, Remote Debugging is the feature that you
will want to enable right away.
@@ -34,10 +34,10 @@ Your IDE will now intercept the current state as the script executes, allowing y
values in memory.
Graphical debuggers make it very easy to step through code, inspect variables, and eval code against the live runtime.
Many IDE's have built-in or plugin-based support for graphical debugging with xdebug. MacGDBp is a free, open-source,
stand-alone xdebug GUI for Mac.
Many IDE's have built-in or plugin-based support for graphical debugging with Xdebug. MacGDBp is a free, open-source,
stand-alone Xdebug GUI for Mac.
* [Learn more about XDebug][xdebug-docs]
* [Learn more about Xdebug][xdebug-docs]
* [Learn more about MacGDBp][macgdbp-install]

View File

@@ -4,16 +4,14 @@ anchor: dependency_management
# Dependency Management {#dependency_management_title}
There are a ton of PHP libraries, frameworks, and components to choose from. Your project will likely use several of
them — these are project dependencies. Until recently, PHP did not have a good way to manage these project
dependencies. Even if you managed them manually, you still had to worry about autoloaders. No more.
There are a ton of PHP libraries, frameworks, and components to choose from. Your project will likely use
several of them — these are project dependencies. Until recently, PHP did not have a good way to manage
these project dependencies. Even if you managed them manually, you still had to worry about autoloaders.
That is no longer an issue.
Currently there are two major package management systems for PHP - Composer and PEAR. Which one is right for you? The
answer is both.
Currently there are two major package management systems for PHP - [Composer] and [PEAR]. Composer is
the main package manager to use for PHP, however for a long time PEAR used to fill that role. Knowing what
PEAR is will be a good idea as you may still find references to it, even if you never use it.
* Use **Composer** when managing dependencies for a single project.
* Use **PEAR** when managing dependencies for PHP as a whole on your system.
In general, Composer packages will be available only in the projects that you explicitly specify whereas a PEAR package
would be available to all of your PHP projects. While PEAR might sound like the easier approach at first glance, there
are advantages to using a project-by-project approach to your dependencies.
[Composer]: /#composer_and_packagist
[PEAR]: /#pear

View File

@@ -10,7 +10,7 @@ with a few simple commands, Composer will automatically download your project's
you.
There are already a lot of PHP libraries that are compatible with Composer, ready to be used in your project. These
"packages" are listed on [Packagist][1], the official repository for Composer-compatible PHP libraries.
"packages" are listed on [Packagist], the official repository for Composer-compatible PHP libraries.
### How to Install Composer
@@ -27,14 +27,16 @@ dependencies.
code online first to confirm it is safe.
#### Installing on Windows
For Windows users the easiest way to get up and running is to use the [ComposerSetup][6] installer, which performs a
global install and sets up your `$PATH` so that you can just call `composer` from any directory in your command line.
For Windows users the easiest way to get up and running is to use the [ComposerSetup] installer, which
performs a global install and sets up your `$PATH` so that you can just call `composer` from any
directory in your command line.
### How to Install Composer (manually)
Manually installing Composer is an advanced technique; however, there are various reasons why a developer might prefer
this method vs. using the interactive installation routine. The interactive installation checks your PHP installation
to ensure that:
Manually installing Composer is an advanced technique; however, there are various reasons why a
developer might prefer this method vs. using the interactive installation routine. The interactive
installation checks your PHP installation to ensure that:
- a sufficient version of PHP is being used
- `.phar` files can be executed correctly
@@ -42,19 +44,19 @@ to ensure that:
- certain problematic extensions are not loaded
- certain `php.ini` settings are set
Since a manual installation performs none of these checks, you have to decide whether the trade-off is worth it for
you. As such, below is how to obtain Composer manually:
Since a manual installation performs none of these checks, you have to decide whether the trade-off is
worth it for you. As such, below is how to obtain Composer manually:
{% highlight console %}
curl -s https://getcomposer.org/composer.phar -o $HOME/local/bin/composer
chmod +x $HOME/local/bin/composer
{% endhighlight %}
The path `$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will
result in a `composer` command being available.
The path `$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment
variable. This will result in a `composer` command being available.
When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that
with:
When you come across documentation that states to run Composer as `php composer.phar install`, you can
substitute that with:
{% highlight console %}
composer install
@@ -64,25 +66,26 @@ This section will assume you have installed composer globally.
### How to Define and Install Dependencies
Composer keeps track of your project's dependencies in a file called `composer.json`. You can manage it by hand if you
like, or use Composer itself. The `composer require` command adds a project dependency and if you don't have a
`composer.json` file, one will be created. Here's an example that adds [Twig][2] as a dependency of your project.
Composer keeps track of your project's dependencies in a file called `composer.json`. You can manage it
by hand if you like, or use Composer itself. The `composer require` command adds a project dependency
and if you don't have a `composer.json` file, one will be created. Here's an example that adds [Twig]
as a dependency of your project.
{% highlight console %}
composer require twig/twig:~1.8
{% endhighlight %}
Alternatively the `composer init` command will guide you through creating a full `composer.json` file for your project.
Either way, once you've created your `composer.json` file you can tell Composer to download and install your
dependencies into the `vendor/` directory. This also applies to projects you've downloaded that already provide a
`composer.json` file:
Alternatively the `composer init` command will guide you through creating a full `composer.json` file
for your project. Either way, once you've created your `composer.json` file you can tell Composer to
download and install your dependencies into the `vendor/` directory. This also applies to projects
you've downloaded that already provide a `composer.json` file:
{% highlight console %}
composer install
{% endhighlight %}
Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your
project dependencies.
Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's
autoloader for your project dependencies.
{% highlight php %}
<?php
@@ -93,32 +96,47 @@ Now you can use your project dependencies, and they'll be autoloaded on demand.
### Updating your dependencies
Composer creates a file called `composer.lock` which stores the exact version of each package it downloaded when you
first ran `php composer.phar install`. If you share your project with other coders and the `composer.lock` file is
part of your distribution, when they run `php composer.phar install` they'll get the same versions as you. To update
your dependencies, run `php composer.phar update`.
Composer creates a file called `composer.lock` which stores the exact version of each package it
downloaded when you
first ran `composer install`. If you share your project with other coders and the `composer.lock` file
is part of your distribution, when they run `composer install` they'll get the same versions as you.
To update your dependencies, run `composer update`.
This is most useful when you define your version requirements flexibly. For instance a version requirement of `~1.8`
means "anything newer than `1.8.0`, but less than `2.0.x-dev`". You can also use the `*` wildcard as in `1.8.*`. Now
Composer's `php composer.phar update` command will upgrade all your dependencies to the newest version that fits the
restrictions you define.
This is most useful when you define your version requirements flexibly. For instance a version
requirement of `~1.8` means "anything newer than `1.8.0`, but less than `2.0.x-dev`". You can also use
the `*` wildcard as in `1.8.*`. Now Composer's `composer update` command will upgrade all your
dependencies to the newest version that fits the restrictions you define.
### Update Notifications
To receive notifications about new version releases you can sign up for [VersionEye][3], a web service that can monitor
your GitHub and BitBucket accounts for `composer.json` files and send emails with new package releases.
To receive notifications about new version releases you can sign up for [VersionEye], a web service
that can monitor your GitHub and BitBucket accounts for `composer.json` files and send emails with new
package releases.
### Checking your dependencies for security issues
The [Security Advisories Checker][4] is a web service and a command-line tool, both will examine your `composer.lock`
The [Security Advisories Checker] is a web service and a command-line tool, both will examine your `composer.lock`
file and tell you if you need to update any of your dependencies.
* [Learn about Composer][5]
### Handling global dependencies with Composer
Composer can also handle global dependencies and their binaries. Usage is straight-forward, all you need
to do is prefix your command with `global`. If per example you wanted to install PHPUnit and have it
available globally, you'd run the following command:
[1]: http://packagist.org/
[2]: http://twig.sensiolabs.org
[3]: https://www.versioneye.com/
[4]: https://security.sensiolabs.org/
[5]: http://getcomposer.org/doc/00-intro.md
[6]: https://getcomposer.org/Composer-Setup.exe
{% highlight console %}
composer global require phpunit/phpunit
{% endhighlight %}
This will create a `~/.composer` folder where your global dependencies reside. To have the installed
packages' binaries available everywhere, you'd then add the `~/.composer/vendor/bin` folder to your
`$PATH` variable.
* [Learn about Composer]
[Packagist]: http://packagist.org/
[Twig]: http://twig.sensiolabs.org
[VersionEye]: https://www.versioneye.com/
[Security Advisories Checker]: https://security.sensiolabs.org/
[Learn about Composer]: http://getcomposer.org/doc/00-intro.md
[ComposerSetup]: https://getcomposer.org/Composer-Setup.exe

View File

@@ -5,7 +5,7 @@ anchor: pear
## PEAR {#pear_title}
Another veteran package manager that many PHP developers enjoy is [PEAR][1]. It behaves much the same way as Composer,
A veteran package manager that some PHP developers enjoy is [PEAR][1]. It behaves similarly to Composer,
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
@@ -17,11 +17,11 @@ version conflicts between two projects arise.
### How to install PEAR
You can install PEAR by downloading the phar installer and executing it. The PEAR documentation has detailed
[install instructions][2] for every operating system.
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 an 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
@@ -56,7 +56,7 @@ handle your PEAR dependencies. This example will install code from `pear2.php.ne
}
{% endhighlight %}
The first section `"repositories"` will be used to let Composer know it should "initialise" (or "discover" in PEAR
The first section `"repositories"` will be used to let Composer know it should "initialize" (or "discover" in PEAR
terminology) the pear repo. Then the require section will prefix the package name like this:
> pear-channel/Package

View File

@@ -38,8 +38,7 @@ Explicitly defining the encoding of your strings in every script will save you a
Additionally, many PHP functions that operate on strings have an optional parameter letting you specify the character
encoding. You should always explicitly indicate UTF-8 when given the option. For example, `htmlentities()` has an
option for character encoding, and you should always specify UTF-8 if dealing with such strings. Note that as of PHP 5.
4.0, UTF-8 is the default encoding for `htmlentities()` and `htmlspecialchars()`.
option for character encoding, and you should always specify UTF-8 if dealing with such strings. Note that as of PHP 5.4.0, UTF-8 is the default encoding for `htmlentities()` and `htmlspecialchars()`.
Finally, If you are building an distributed application and cannot be certain that the `mbstring` extension will be
enabled, then consider using the [patchwork/utf8] Composer package. This will use `mbstring` if it is available, and
@@ -86,7 +85,7 @@ $string = mb_substr($string, 0, 15);
// Connect to a database to store the transformed string
// See the PDO example in this document for more information
// Note the `set names utf8mb4` commmand!
// Note the `charset=utf8mb4` in the Data Source Name (DSN)
$link = new PDO(
'mysql:host=your-hostname;dbname=your-db;charset=utf8mb4',
'your-username',
@@ -150,3 +149,4 @@ header('Content-Type: text/html; charset=UTF-8');
* [Stack Overflow: Best practices in PHP and MySQL with international strings](http://stackoverflow.com/questions/140728/best-practices-in-php-and-mysql-with-international-strings)
* [How to support full Unicode in MySQL databases](http://mathiasbynens.be/notes/mysql-utf8mb4)
* [Bringing Unicode to PHP with Portable UTF-8](http://www.sitepoint.com/bringing-unicode-to-php-with-portable-utf8/)
* [Stack Overflow: DOMDocument loadHTML does not encode UTF-8 correctly](http://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly)

View File

@@ -50,13 +50,16 @@ FROM users` which will delete all of your users! Instead, you should sanitize th
<?php
$pdo = new PDO('sqlite:/path/db/users.db');
$stmt = $pdo->prepare('SELECT name FROM users WHERE id = :id');
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT); // <-- Automatically sanitized by PDO
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // <-- filter your data first (see [Data Filtering](#data_filtering)), especially important for INSERT, UPDATE, etc.
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // <-- Automatically sanitized for SQL by PDO
$stmt->execute();
{% endhighlight %}
This is correct code. It uses a bound parameter on a PDO statement. This escapes the foreign input ID before it is
introduced to the database preventing potential SQL injection attacks.
For writes, such as INSERT or UPDATE, it's especially critical to still [filter your data](#data_filtering) first and sanitize it for other things (removal of HTML tags, JavaScript, etc). PDO will only sanitize it for SQL, not for your application.
* [Learn about PDO]
You should also be aware that database connections use up resources and it was not unheard-of to have resources

View File

@@ -65,7 +65,7 @@ include 'views/foo-list.php';
{% highlight php %}
<?php
class Foo()
class FooModel()
{
protected $db;

View File

@@ -18,7 +18,7 @@ there is a slight performance hit, however this is very minimal when proper cach
Using the [Twig] library.
{% highlight text %}
{% highlight html+jinja %}
{% raw %}
{% include 'header.html' with {'title': 'User Profile'} %}
@@ -33,7 +33,7 @@ Using the [Twig] library.
Using the [Twig] library.
{% highlight text %}
{% highlight html+jinja %}
{% raw %}
// template.html
@@ -52,7 +52,7 @@ Using the [Twig] library.
{% endraw %}
{% endhighlight %}
{% highlight text %}
{% highlight html+jinja %}
{% raw %}
// user_profile.html

View File

@@ -96,7 +96,7 @@ for the existence of the file before you try to load it, but if the file is dele
is potentially something PHP should resolve, but is one case where error suppression might seem like the only valid
solution.
Earlier we mentioned there's no way in a stock PHP system to turn off the error control operator. However, [xDebug] has
Earlier we mentioned there's no way in a stock PHP system to turn off the error control operator. However, [Xdebug] has
an `xdebug.scream` ini setting which will disable the error control operator. You can set this via your `php.ini` file
with the following.
@@ -111,7 +111,7 @@ You can also set this value at runtime with the `ini_set` function
ini_set('xdebug.scream', '1')
{% endhighlight %}
The "[Scream]" PHP extension offers similar functionality to xDebug's, although Scream's ini setting is named
The "[Scream]" PHP extension offers similar functionality to Xdebug's, although Scream's ini setting is named
`scream.enabled`.
This is most useful when you're debugging code and suspect an informative error is suppressed. Use scream with care,
@@ -121,7 +121,7 @@ disabled.
* [Error Control Operators]
* [SitePoint]
* [xDebug]
* [Xdebug]
* [Scream]
@@ -149,7 +149,7 @@ More information on this and details on how to use `ErrorException` with error h
[errorreport]: /#error_reporting
[xDebug]: http://xdebug.org/docs/basic
[Xdebug]: http://xdebug.org/docs/basic
[Scream]: http://php.net/book.scream
[Error Control Operators]: http://php.net/language.operators.errorcontrol
[SitePoint]: http://www.sitepoint.com/

View File

@@ -44,7 +44,7 @@ developers interested in Capistrano.
[Chef] is more than a deployment framework, it is a very powerful Ruby based system integration framework that doesn't
just deploy your app but can build your whole server environment or virtual boxes.
[Deployer] is a deployment tool written in PHP, it's simple and functional. Deploy your code to all servers you want, it supports deploy via copy, or via VCS (like git), or via rsync. Run your tasks on all your servers, or use our recipes of common tasks for Symfony, Laravel, Zend Framework and Yii.
[Deployer] is a deployment tool written in PHP, it's simple and functional. Runs tasks in parallel, atomic deployment, keeps consistency between servers. Recipes of common tasks for Symfony, Laravel, Zend Framework and Yii.
#### Chef resources for PHP developers:
@@ -91,4 +91,4 @@ PHP.
[Jenkins]: http://jenkins-ci.org/
[PHPCI]: http://www.phptesting.org/
[Teamcity]: http://www.jetbrains.com/teamcity/
[Deployer]: http://deployer.in/
[Deployer]: http://deployer.org/

View File

@@ -5,7 +5,7 @@ anchor: vagrant
## Vagrant {#vagrant_title}
[Vagrant] helps you building your virtual boxes on top of the known virtual environments and will configure these
[Vagrant] helps you build your virtual boxes on top of the known virtual environments and will configure these
environments based on a single configuration file. These boxes can be set up manually, or you can use "provisioning"
software such as [Puppet] or [Chef] to do this for you. Provisioning the base box is a great way to ensure that
multiple boxes are set up in an identical fashion and removes the need for you to maintain complicated "set up"
@@ -19,13 +19,13 @@ create and edit your files on your host machine and then run the code inside you
If you need a little help to start using Vagrant there are some services that might be useful:
- [Rove]: service that allows you to pre-generate typical Vagrant builds, PHP among the options. The provisioning is
- [Rove][Rove]: service that allows you to pre-generate typical Vagrant builds, PHP among the options. The provisioning is
made with Chef.
- [Puphpet]: simple GUI to set up virtual machines for PHP development. **Heavily focused in PHP**. Besides local VMs,
- [Puphpet][Puphpet]: simple GUI to set up virtual machines for PHP development. **Heavily focused in PHP**. Besides local VMs,
it can be used to deploy to cloud services as well. The provisioning is made with Puppet.
- [ Protobox]: is a layer on top of vagrant and a web GUI to setup virtual machines for web development. A single YAML
- [Protobox][Protobox]: is a layer on top of vagrant and a web GUI to setup virtual machines for web development. A single YAML
document controls everything that is installed on the virtual machine.
- [Phansible]: provides an easy to use interface that helps you generate Ansible Playbooks for PHP based projects.
- [Phansible][Phansible]: provides an easy to use interface that helps you generate Ansible Playbooks for PHP based projects.
[Vagrant]: http://vagrantup.com/

View File

@@ -16,15 +16,15 @@ Below is an example of how you might document a class with a few methods;
/**
* @author A Name <a.name@example.com>
* @link http://www.phpdoc.org/docs/latest/index.html
* @package helper
*/
class DateTimeHelper
{
/**
* @param mixed $anything Anything that we can convert to a \DateTime object
*
* @return \DateTime
* @throws \InvalidArgumentException
*
* @return \DateTime
*/
public function dateTimeFromAnything($anything)
{
@@ -59,10 +59,9 @@ class DateTimeHelper
}
{% endhighlight %}
The documentation for the class as a whole firstly has the [@author] tag, this tag is used to document the author of
the code and can be repeated for documenting several authors. Secondly is the [@link] tag, used to link to a website
indicating a relationship between the website and the code. Thirdly it has the [@package] tag, used to categorize the
code.
The documentation for the class as a whole has the [@author] tag and a [@link] tag. The [@author] tag is used to
document the author of the code and can be repeated for documenting several authors. The [@link] tag is used to link to
a website indicating a relationship between the website and the code.
Inside the class, the first method has an [@param] tag documenting the type, name and description of the parameter
being passed to the method. Additionally it has the [@return] and [@throws] tags for documenting the return type, and
@@ -78,7 +77,6 @@ results in the same (no return) action.
[PHPDoc manual]: http://www.phpdoc.org/docs/latest/index.html
[@author]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/author.html
[@link]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/link.html
[@package]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html
[@param]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html
[@return]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html
[@throws]: http://www.phpdoc.org/docs/latest/references/phpdoc/tags/throws.html

22
_posts/16-08-01-Sites.md Normal file
View File

@@ -0,0 +1,22 @@
---
isChild: true
anchor: other_resources
title: Other Useful Resources
---
## Other Useful Resources {#other_resources_title}
### Cheatsheets
* [PHP Cheatsheets](http://phpcheatsheets.com/) - for variable comparisons, arithmetics and variable testing in various
PHP versions
* [PHP Security Cheatsheet](https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet)
### More best practices
* [PHP Best Practices](https://phpbestpractices.org/)
* [Best practices for Modern PHP Development](https://www.airpair.com/php/posts/best-practices-for-modern-php-development)
### PHP universe
* [PHP Developer blog](http://blog.phpdeveloper.org/)

18
_posts/16-09-01-Videos.md Normal file
View File

@@ -0,0 +1,18 @@
---
isChild: true
anchor: videos
title: Video Tutorials
---
### Youtube Channels
* [PHP Academy](https://www.youtube.com/user/phpacademy)
* [The New Boston](https://www.youtube.com/user/thenewboston)
* [Sherif Ramadan](https://www.youtube.com/user/businessgeek)
* [Level Up Tuts](https://www.youtube.com/user/LevelUpTuts)
### Paid Videos
* [Standards and Best practices](http://teamtreehouse.com/library/standards-and-best-practices)
* [PHP Training on Pluralsight](http://www.pluralsight.com/search/?searchTerm=php)
* [PHP Training on Lynda.com](http://www.lynda.com/search?q=php)
* [PHP Training on Tutsplus](http://code.tutsplus.com/categories/php/courses)

View File

@@ -2,6 +2,7 @@
layout: default
title: Website Banners
description: "Spread the word! Use these banner to let new PHP programmers know about PHP: The Right Way"
sitemap: true
---
# Web Banners

View File

@@ -1,6 +1,7 @@
---
layout: default
description: "An easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative PHP tutorials around the Web"
sitemap: true
---
{% capture welcome_content %}{% include welcome.md %}{% endcapture %}

View File

@@ -1,6 +1,7 @@
---
layout: page
title: Design Patterns
sitemap: true
---
# Design Patterns

View File

@@ -1,6 +1,7 @@
---
layout: page
title: Functional Programming in PHP
sitemap: true
---
# Functional Programming in PHP

View File

@@ -1,6 +1,7 @@
---
layout: page
title: The Basics
sitemap: true
---
# The Basics
@@ -35,6 +36,7 @@ if (strpos('testing', 'test') !== false) { // true, as strict comparison was
* [Comparison operators](http://php.net/language.operators.comparison)
* [Comparison table](http://php.net/types.comparisons)
* [Comparison cheatsheet](http://phpcheatsheets.com/index.php?page=compare)
## Conditional statements
@@ -295,7 +297,7 @@ If you are concatenating multiple strings of any type, or interpolate values int
results can vary. If you are working with a small number of values, concatenation is minutely faster. With a lot of
values, interpolating is minutely faster.
Regardless of what you are doing with strings, none of the types will ever have any noticable impact on your
Regardless of what you are doing with strings, none of the types will ever have any noticeable impact on your
application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this micro-
optimization unless you really understand the meaning and impact of the differences.

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.phptherightway.com/index.html</loc>
<lastmod>2012-07-07T01:00:00-05:00</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>http://www.phptherightway.com/banners.html</loc>
<lastmod>2012-07-08T14:11:00-05:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
</urlset>