mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-06 14:06:34 +02:00
Minor (non-quote) grammar/spelling fixes
This commit is contained in:
@@ -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/
|
||||
|
@@ -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.
|
||||
|
@@ -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()`.
|
||||
|
@@ -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:
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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]
|
||||
|
@@ -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 %}
|
||||
<?php
|
||||
|
@@ -6,13 +6,13 @@ isChild: true
|
||||
|
||||
Eventually everyone builds a PHP application that relies on user login. Usernames and passwords are stored in a database and later used to authenticate users upon login.
|
||||
|
||||
It is important that you properly [_hash_][3] passwords before storing them. Password hashing is an irreversible, one way function performed against the users password. This produces a fixed-length string that can not be feasibly reversed. This means you can compare a hash against another to determine if they both came from the same source string, but you can not determine the original string. If passwords are not hashed and your database is accessed by an unauthorized third-party, all user accounts are now compromised. Some users may (unfortunately) use the same password for other services. Therefore, it is important to take security seriously.
|
||||
It is important that you properly [_hash_][3] passwords before storing them. Password hashing is an irreversible, one way function performed against the user's password. This produces a fixed-length string that cannot be feasibly reversed. This means you can compare a hash against another to determine if they both came from the same source string, but you cannot determine the original string. If passwords are not hashed and your database is accessed by an unauthorized third-party, all user accounts are now compromised. Some users may (unfortunately) use the same password for other services. Therefore, it is important to take security seriously.
|
||||
|
||||
**Hashing passwords with `password_hash`**
|
||||
|
||||
In PHP 5.5 `password_hash` was introduced. At this time it is using BCrypt, the strongest algorithm currently supported by PHP. It will be updated in the future to support more algorithms as needed though. The `password_compat` library was created to provide forward compatibility for 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 %}
|
||||
<?php
|
||||
|
@@ -10,6 +10,6 @@ be followed:
|
||||
- It is recommended that you store your configuration information where it cannot be accessed directly and pulled in
|
||||
via the file system.
|
||||
- If you must store your configuration files in the document root, name the files with a `.php` extension. This
|
||||
ensures that, even if the script is accessed directly, it will not be outputed as plain text.
|
||||
ensures that, even if the script is accessed directly, it will not be output as plain text.
|
||||
- Information in configuration files should be protected accordingly, either through encryption or group/user file
|
||||
system permissions
|
@@ -1,4 +1,4 @@
|
||||
# Caching {#caching_title}
|
||||
|
||||
PHP is pretty quick by itself, but bottlenecks can arise when you make remote connections, load files, etc.
|
||||
Thankfully, there are various tools available to speed up certain parts of your application, or reduce the number of times these various time consuming tasks need to run.
|
||||
Thankfully, there are various tools available to speed up certain parts of your application, or reduce the number of times these various time-consuming tasks need to run.
|
Reference in New Issue
Block a user