diff --git a/_posts/03-05-01-Command-Line-Interface.md b/_posts/03-05-01-Command-Line-Interface.md index a9c7de5..846ab34 100644 --- a/_posts/03-05-01-Command-Line-Interface.md +++ b/_posts/03-05-01-Command-Line-Interface.md @@ -27,11 +27,11 @@ Let's write a simple "Hello, $name" CLI program. To try it out, create a file na {% highlight php %} .\n"; + echo "Usage: php hello.php " . PHP_EOL; exit(1); } $name = $argv[1]; -echo "Hello, $name\n"; +echo "Hello, $name" . PHP_EOL; {% endhighlight %} PHP sets up two special variables based on the arguments your script is run with. [`$argc`][argc] is an integer diff --git a/_posts/05-03-01-Date-and-Time.md b/_posts/05-03-01-Date-and-Time.md index a6a1cef..2837c8e 100644 --- a/_posts/05-03-01-Date-and-Time.md +++ b/_posts/05-03-01-Date-and-Time.md @@ -19,7 +19,7 @@ output. $raw = '22. 11. 1968'; $start = DateTime::createFromFormat('d. m. Y', $raw); -echo 'Start date: ' . $start->format('Y-m-d') . "\n"; +echo 'Start date: ' . $start->format('Y-m-d') . PHP_EOL; {% endhighlight %} Calculating with DateTime is possible with the DateInterval class. DateTime has methods like `add()` and `sub()` that @@ -34,7 +34,7 @@ $end = clone $start; $end->add(new DateInterval('P1M6D')); $diff = $end->diff($start); -echo 'Difference: ' . $diff->format('%m month, %d days (total: %a days)') . "\n"; +echo 'Difference: ' . $diff->format('%m month, %d days (total: %a days)') . PHP_EOL; // Difference: 1 month, 6 days (total: 37 days) {% endhighlight %} @@ -43,8 +43,7 @@ You can use standard comparisons on DateTime objects: {% highlight php %} getMakeAndModel()); // outputs "Bugatti Veyron" This code uses a factory to create the Automobile object. There are two possible benefits to building your code this way; the first is that if you need to change, rename, or replace the Automobile class later on you can do so and you will only have to modify the code in the factory, instead of every place in your project that uses the Automobile class. -The second possible benefit is that if creating the object is a complicated job you can do all of the work in the -factory, instead of repeating it every time you want to create a new instance. +The second possible benefit is that, if creating the object is a complicated job, you can do all of the work in the +factory instead of repeating it every time you want to create a new instance. Using the factory pattern isn't always necessary (or wise). The example code used here is so simple that a factory would simply be adding unneeded complexity. However if you are making a fairly large or complex project you may save