Skip to content

Commit

Permalink
Concepts adjustments (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnkmpf authored Sep 2, 2023
1 parent 643adb1 commit 2ec1240
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions concepts/anonymous-functions-closures/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PHP also has a shorter function syntax called `arrow functions`. They are requir
fn(arguments) => expression
```

In this function style, you do not need to use `use`. It will automatically closed over and capture any values in the parent scope. The expression in these arrow functions is automatically returned without needing to use the `return` keyword. That would allow us to rewrite the `onlyOdds` function above like so:
In this function style, you do not need to use `use`. It will automatically close over and capture any values in the parent scope. The expression in these arrow functions is automatically returned without needing to use the `return` keyword. That would allow us to rewrite the `onlyOdds` function above like so:

```php
function onlyOdds(array $numbers): array
Expand Down Expand Up @@ -64,7 +64,7 @@ function positiveAverage(array $numbers): float
$count = 0;
return array_walk(
$numbers,
function($num) use (&$count, %$toal) {
function($num) use (&$count, &$total) {
$total += abs($num);
$count++;
}
Expand Down
2 changes: 1 addition & 1 deletion concepts/foreach-loops/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"authors": [
"neenjaw"
],
"contributors": []
"contributors": ["vnkmpf"]
}
10 changes: 0 additions & 10 deletions concepts/foreach-loops/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,3 @@ foreach (iterable as $key => $value) {
}
```

When iterating arrays, it is possible to modify the original array by preceding the `$value` with `&`:

```php
foreach (iterable as &$value) {
// statements
}
unset($value);
```

However, `$value` persists after the `foreach` block so it is **strongly** recommended to break the reference using `unset($value)` after the block.
8 changes: 4 additions & 4 deletions concepts/readonly-properties/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The property is allowed to be assigned once, but any attempt to re-assign or mod
class Block
{
public function __construct(
public readonly int $length;
public readonly int $width;
public readonly int $length,
public readonly int $width,
) {
}
}
Expand All @@ -26,8 +26,8 @@ Additionally it prevents the addition of dynamic properties.
readonly class Block
{
public function __construct(
public int $length;
public int $width;
public int $length,
public int $width,
) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion concepts/scope-resolution-operator/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AnotherClass extends MyClass
// (new AnotherClass())->getMaximum() => 10
```

Most commonly in object oriented programming `parent` is used to call the call the parent constructor when an object is being instantiated:
Most commonly in object oriented programming `parent` is used to call the parent constructor when an object is being instantiated:

```php
class ChildClass extends ParentClass
Expand Down
2 changes: 1 addition & 1 deletion concepts/ternary-operator/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The obvious benefit of using a ternary operator is brevity, such that it is shor
}

$needExactAnswer = false;
$estimatedAnswer = 40
$estimatedAnswer = 40;
$answer = $needExactAnswer ? expensiveCalculation() : $estimatedAnswer;
```

Expand Down
2 changes: 1 addition & 1 deletion concepts/union-types/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"authors": [
"neenjaw"
],
"contributors": ["dstockto"]
"contributors": ["dstockto","vnkmpf"]
}
3 changes: 1 addition & 2 deletions concepts/union-types/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function add(int|float $a, int|float $b): int|float

## Nuances

- `null` cannot be used as a standalone type, but types may be declared _nullable_ by either using `?Type` or `Type1|Type2|null`.
- `false` cannot be used as a standalone type, and is included for historical reasons, as many legacy functions may return `false` when an error is encountered.
- `null` types may be declared _nullable_ by either using `?Type` or `Type1|Type2|null`.
- declared duplicate or redundant types will result in a compile-time error.
- `void` cannot be used as part of a union type declaration.
15 changes: 10 additions & 5 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Which version to chose?

We encourage to use a stable PHP release with active support. Currently this is **PHP 7.3, 7.4 and 8.0**. Details on current releases and their timelines can be found at [php.net/supported-versions](https://www.php.net/supported-versions.php). PHP 7.3 is only supported until December 2021, so PHP 7.4 or 8.0 are preferred. Version 8.1 will be available in late November 2021.
We encourage to use a stable PHP release with active support. Currently this is **PHP 8.0, 8.1 and 8.2**. Details on current releases and their timelines can be found at [php.net/supported-versions](https://www.php.net/supported-versions.php).

## Install PHP

Expand Down Expand Up @@ -30,19 +30,19 @@ For further instructions, read the manual on [Installation on Unix systems](http

### macOS

While PHP is often bundled with macOS, it is often outdated. We recommended installing php through [Homebrew](https://brew.sh/). You can install Homebrew following the instructions [here](https://brew.sh/#install).
While PHP is often bundled with macOS, it is often outdated. We recommended installing PHP through [Homebrew](https://brew.sh/). You can install Homebrew following the instructions [here](https://brew.sh/#install).

To confirm its installation try the following command, it should output Homebrew `3.2.x` at the time of this writing.
```bash
$ brew --version
```

Install php via homebrew
Install PHP via homebrew
```bash
$ brew install [email protected]
```

This should display the now installed version of php, at least version `8.0.x`.
This should display the now installed version of PHP, at least version `8.0.x`.
```bash
$ php -v
```
Expand All @@ -57,6 +57,11 @@ There are pre-built stacks including [WAMP](https://www.wampserver.com/en/) - (W

For further instructions, read the manual on [Installation on Windows systems](https://www.php.net/manual/en/install.windows.php).

### Docker

If you prefer containerized solutions, you can download [official PHP image from Docker Hub](https://hub.docker.com/_/php).
You will also need [Docker](https://docs.docker.com/engine/install/).

### Other

If you want to use a different OS, see instruction on [php.net/manual/en/install](https://www.php.net/manual/en/install.php).
Expand All @@ -74,7 +79,7 @@ PHPUnit version 9 can be installed globally via [Composer](https://getcomposer.o
> composer global require phpunit/phpunit ^9
```

It you are using PHP 8+ make sure you install at version 9.5 or later.
If you are using PHP 8+ make sure you install at version 9.5 or later.

#### Manual installation

Expand Down

0 comments on commit 2ec1240

Please sign in to comment.