Merge branch 'codeguy:gh-pages' into gh-pages

This commit is contained in:
kanlukasz
2021-09-22 07:54:14 +02:00
committed by GitHub
5 changed files with 7 additions and 17 deletions

View File

@@ -27,11 +27,11 @@ Let's write a simple "Hello, $name" CLI program. To try it out, create a file na
{% highlight php %}
<?php
if ($argc !== 2) {
echo "Usage: php hello.php <name>.\n";
echo "Usage: php hello.php <name>" . 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

View File

@@ -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 %}
<?php
if ($start < $end) {
echo "Start is before the end!\n";
}
echo "Start is before the end!" . PHP_EOL;}
{% endhighlight %}
One last example to demonstrate the DatePeriod class. It is used to iterate over recurring events. It can take two

View File

@@ -1,8 +0,0 @@
---
isChild: true
anchor: mentoring
---
## Mentoring {#mentoring_title}
* [php-mentoring.org](https://php-mentoring.org/) - Formal, peer to peer mentoring in the PHP community.

View File

@@ -15,7 +15,6 @@ PHP versions
### 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)
* [Why You Should Be Using Supported PHP Versions](https://kinsta.com/blog/php-versions/)
### News around the PHP and web development communities

View File

@@ -54,8 +54,8 @@ print_r($veyron->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