mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-08 06:56:33 +02:00
Grammar/Spelling corrections
This commit is contained in:
@@ -14,10 +14,10 @@ problem stems from strict comparisons (the comparison of booleans as integers).
|
|||||||
<?php
|
<?php
|
||||||
$a = 5; // 5 as an integer
|
$a = 5; // 5 as an integer
|
||||||
|
|
||||||
var_dump($a == 5); // compares value; return true
|
var_dump($a == 5); // compare value; return true
|
||||||
var_dump($a == '5'); // compares value (ignore type); return true
|
var_dump($a == '5'); // compare value (ignore type); return true
|
||||||
var_dump($a === 5); // compares type/value (integer vs. integer); return true
|
var_dump($a === 5); // compare type/value (integer vs. integer); return true
|
||||||
var_dump($a === '5'); // compares type/value (integer vs. string); return false
|
var_dump($a === '5'); // compare type/value (integer vs. string); return false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strict comparisons
|
* Strict comparisons
|
||||||
@@ -113,14 +113,14 @@ namespace phptherightway;
|
|||||||
|
|
||||||
function fopen()
|
function fopen()
|
||||||
{
|
{
|
||||||
$file = \fopen(); // our function name is the same as an internal function.
|
$file = \fopen(); // our function name is the same as an internal function
|
||||||
// execute globally by adding "\".
|
// execute globally by adding '\'.
|
||||||
}
|
}
|
||||||
|
|
||||||
function array()
|
function array()
|
||||||
{
|
{
|
||||||
$iterator = new \ArrayIterator(); // ArrayIterator is an internal class. Using it without a backslash
|
$iterator = new \ArrayIterator(); // ArrayIterator is an internal class. Using it without a backslash
|
||||||
// will execute it within the namespace scope.
|
// will execute it within the namespace scope
|
||||||
}
|
}
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ differences between the string types and their benefits/uses.
|
|||||||
|
|
||||||
#### Single quotes
|
#### Single quotes
|
||||||
|
|
||||||
Single quotes are the simplest way to define a string and are often the quickest. Their quickness stems from PHP not
|
Single quotes are the simplest way to define a string and are often the quickest. Their speed stems from PHP not
|
||||||
parsing the string (doesn't parse for variables). They're best suited for:
|
parsing the string (doesn't parse for variables). They're best suited for:
|
||||||
|
|
||||||
- Strings that do not need to be parsed
|
- Strings that do not need to be parsed
|
||||||
@@ -188,14 +188,14 @@ suited for:
|
|||||||
|
|
||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
<?php
|
<?php
|
||||||
echo 'phptherightway\'s is ' . $adjective . '.' // a single quotes example that uses multiple concatenating for
|
echo 'phptherightway is ' . $adjective . '.' // a single quotes example that uses multiple concatenating for
|
||||||
. "\n" // variables and escaped string
|
. "\n" // variables and escaped string
|
||||||
. 'I love learning' . $code . '!';
|
. 'I love learning' . $code . '!';
|
||||||
|
|
||||||
vs.
|
vs.
|
||||||
|
|
||||||
echo "phptherightway's is $adjective.\n I love learning $code!" // Instead of multiple concatenating, double quotes
|
echo "phptherightway is $adjective.\n I love learning $code!" // Instead of multiple concatenating, double quotes
|
||||||
// enables us to use a parsable string
|
// enables us to use a parsable string
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
While using double quotes that contain variables, it's often the case that the variable will be touching another
|
While using double quotes that contain variables, it's often the case that the variable will be touching another
|
||||||
@@ -216,7 +216,7 @@ echo "I drank some juice made of {$juice}s"; // $juice will be parsed
|
|||||||
* Complex variables will also be parsed within curly brackets
|
* Complex variables will also be parsed within curly brackets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$juice = array('apple', 'orange', 'juice');
|
$juice = array('apple', 'orange', 'plum');
|
||||||
echo "I drank some juice made of {$juice[1]}s"; // $juice[1] will be parsed
|
echo "I drank some juice made of {$juice[1]}s"; // $juice[1] will be parsed
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ $a = 'Variables';
|
|||||||
$str = <<<EOD // initialized by <<<
|
$str = <<<EOD // initialized by <<<
|
||||||
Example of string
|
Example of string
|
||||||
spanning multiple lines
|
spanning multiple lines
|
||||||
using nowdoc syntax.
|
using heredoc syntax.
|
||||||
$a are parsed.
|
$a are parsed.
|
||||||
EOD; // closing 'EOD' must be on it's own line, and to the left most point
|
EOD; // closing 'EOD' must be on it's own line, and to the left most point
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ EOD; // closing 'EOD' must be on it's own line, and to th
|
|||||||
*
|
*
|
||||||
* Example of string
|
* Example of string
|
||||||
* spanning multiple lines
|
* spanning multiple lines
|
||||||
* using nowdoc syntax.
|
* using heredoc syntax.
|
||||||
* Variables are parsed.
|
* Variables are parsed.
|
||||||
*/
|
*/
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
@@ -307,7 +307,8 @@ echo ($a == 5) ? return true : return false; // this example will output an e
|
|||||||
|
|
||||||
At times, coders attempt to make their code "cleaner" by declaring predefined variables with a different name. What
|
At times, coders attempt to make their code "cleaner" by declaring predefined variables with a different name. What
|
||||||
this does in reality is to double the memory consumption of said script. For the example below, let's say
|
this does in reality is to double the memory consumption of said script. For the example below, let's say
|
||||||
an example string of text contains 1MB worth of data, by copying the variable you've increased the scripts execution to 2MB.
|
an example string of text contains 1MB worth of data, by copying the variable you've increased the scripts execution to
|
||||||
|
2MB.
|
||||||
|
|
||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
<?php
|
<?php
|
||||||
@@ -319,4 +320,4 @@ vs.
|
|||||||
echo 'A very long string of text'; // uses 1MB memory
|
echo 'A very long string of text'; // uses 1MB memory
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
* [Performace tips](https://developers.google.com/speed/articles/optimizing-php)
|
* [Performace tips](https://developers.google.com/speed/articles/optimizing-php)
|
Reference in New Issue
Block a user