# PHP Notes

## [**https://phptherightway.com/**](https://phptherightway.com/)

You can find useful tutorials online for Laravel in the[ Laravel documentation](https://laravel.com/docs/6.x?ref=hackernoon.com),[ Laracasts discussion forum](https://laracasts.com/discuss?ref=hackernoon.com),[ Treehouse](https://teamtreehouse.com/community/laravel-5?ref=hackernoon.com),[ Sitepoint](https://www.sitepoint.com/php/laravel-php/?ref=hackernoon.com), and[ Codebright](https://daylerees.com/codebright/?ref=hackernoon.com).

The Laravel[ Github docs](https://github.com/laravel/laravel?ref=hackernoon.com) are also extensive and provide excellent information that Symfony doesn’t provide.

**Книга Symfony:**

{% embed url="<https://symfony.com/doc/current/the-fast-track/en/index.html>" %}

**Symfony profiling:**

[**https://symfony.com/doc/current/profiler.html?ref=hackernoon.com**](https://symfony.com/doc/current/profiler.html?ref=hackernoon.com)

## [**https://www.toptal.com/php/choosing-between-symfony-and-laravel-frameworks**](https://www.toptal.com/php/choosing-between-symfony-and-laravel-frameworks)

## [**https://thephp.website/en/issue/how-does-php-engine-actually-work/**](https://thephp.website/en/issue/how-does-php-engine-actually-work/)

## [**https://hostadvice.com/how-to/how-to-deploy-a-php-application-using-docker-compose/**](https://hostadvice.com/how-to/how-to-deploy-a-php-application-using-docker-compose/)

## [**https://stackoverflow.com/questions/49302298/docker-crontab-not-found**](https://stackoverflow.com/questions/49302298/docker-crontab-not-found)

## **Как использовать yield?**:

yield + return

<https://medium.com/just-tech/working-with-php-generators-57586e61f19a>

```
$gen = (function() {
    yield 1;
    yield 2;
    // 3 is only returned after the generator has finished
    return 3;

})();

foreach ($gen as $val) {
    echo $val, PHP_EOL;
}

echo $gen->getReturn(), PHP_EOL;

// Outputs 1 2 3
```

## Как использовать Generator?:

{% embed url="<https://theiconic.tech/why-and-when-to-use-generator-instead-of-array-in-php-fe5c60231746>" %}

[**https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html**](https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html)

{% embed url="<https://www.php.net/manual/en/language.generators.overview.php>" %}

{% embed url="<https://alanstorm.com/php-generators-from-scratch/>" %}

{% embed url="<https://sergeyzhuk.me/2018/10/26/from-promise-to-coroutines/>" %}

[**https://medium.com/just-tech/working-with-php-generators-57586e61f19a**](https://medium.com/just-tech/working-with-php-generators-57586e61f19a)

A generator allows you to write code that uses [foreach](https://www.php.net/manual/en/control-structures.foreach.php) to iterate over a set of data without needing to build an array in memory, which may cause you to exceed a memory limit, or require a considerable amount of processing time to generate.&#x20;

```
<?php
function xrange($start, $limit, $step = 1) {
    if ($start <= $limit) {
        if ($step <= 0) {
            throw new LogicException('Step must be positive');
        }

        for ($i = $start; $i <= $limit; $i += $step) {
            yield $i;
        }
    } else {
        if ($step >= 0) {
            throw new LogicException('Step must be negative');
        }

        for ($i = $start; $i >= $limit; $i += $step) {
            yield $i;
        }
    }
}

/*
 * Note that both range() and xrange() result in the same
 * output below.
 */

echo 'Single digit odd numbers from range():  ';
foreach (range(1, 9, 2) as $number) {
    echo "$number ";
}
echo "\n";

echo 'Single digit odd numbers from xrange(): ';
foreach (xrange(1, 9, 2) as $number) {
    echo "$number ";
}
?>
```

## **Что за конструкция** **static function (как аргумент)?**

{% embed url="<https://dev.to/ryancco/the-power-of-static-in-php-4130>" %}

```
class PostsCollectionFilter
{
    public function unpublished($posts)
    {
        return $posts->filter(static function ($post) {
            return ! $post->published;
        });
    }
}
```

**В общем статическая анонимная функция прибавляет немного производительности в отличие от обычной анонимной функции. Если нам не нужен $this в этой фнкции, то мы можем указать static, но это некритично.**

It is worth noting that in context of a class, static anonymous functions yield micro performance improvements and may be suggested in any instances which you do not need the containing class to be bound to the anonymous function.

## **Как используются замыкания в PHP?**

<https://wiki.php.net/rfc/closures>

## **Для чего нужно** Late Static Bindings?

**Чтобы вызвать метод в контексте не где он объявлен, а где вызван:**

[**https://www.youtube.com/watch?v=MxRrCV\_3VSQ**](https://www.youtube.com/watch?v=MxRrCV_3VSQ)

```
class Book{

    public static $name = 'Kirill';
    
    public static function author()
    {
        return "the author name is ". self::$name;
    
    }
    
    public static function getAuthor(){
        echo static::author();
    }
}

class NewBook{

    
    public static function author()
    {
        return "the author name is ". self::$name . " and K";
    
    }
    
   
}

Book::getAuthor(); //he author name is Kirill
NewBook::getAuthor(); //he author name is Kirill and K
```

## **Когда использовать immutable objects?**

## **Посмотреть инструмент PHP metrics.**

<https://www.phpmetrics.org/>

## Те**стирование:**

**Посмотреть, как они делаются здесь.**

[**https://github.com/yiisoft/validator**](https://github.com/yiisoft/validator)

Сайт, на котором собран 61 PHP-инструмент для анализа кода, управления зависимостями, тестов: <https://phpqa.io/>\
\
А в этом репозитории ещё свыше ста линтеров, форматтеров и статических анализаторов: <https://tprg.ru/lptv>\
\
\#php #инструменты[t.me/tproger\_web/1004](https://t.me/tproger_web/1004)

**PHPStorm auto indent**

<https://plugins.jetbrains.com/plugin/7642-save-actions><br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kymbrik3.gitbook.io/programming/php-notes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
