Quantcast
Channel: PHP Annotated Monthly : The PhpStorm Blog | The JetBrains Blog
Viewing all 104 articles
Browse latest View live

PHP Annotated – July 2019

$
0
0

php_annotated

Greetings everyone,

In our July’s edition of PHP Annotated, you can read about the latest on the PHP 7.4.0 alpha 3 release, ReactPHP 1.0 LTS, new proposals from PHP Internals, such as the Strict operators directive, as well as links for Laravel and Symfony, useful tools, videos, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Normalize arrays’ “auto-increment” value on copy on write – This RFC proposes to reset the “autoincrement” value when an array is being copied-on-write. As if a new empty array was created and then filled up entry-by-entry from the old one.
    $array = [0, 1, 2, 3];
            unset($array[3], $array[2]);
            $arrayCopy = $array;
            $arrayCopy[] = 2;
    
            // If the proposal is accepted, the following statement will be true.
            // Currently, the arrays below are not equivalent.
            assert($arrayCopy === [0, 1, 2]);

  • [RFC] Strict operators directive – PHP performs implicit type casting for most operators. The rules of conversion are complex and may lead to surprising results. This RFC proposes to introduce a new directive strict_operators, which will limit type conversions and make them throw TypeError for incompatible operands. The document describes in detail the current and proposed behaviors and has many examples. So far, it has been postponed until PHP 8.0, as the change is too big for 7.4. .
  • 🔈 PHP Internals News #17: – With Theodore Brown and Bishop Bettini about Numeric Literal Separator.
  • 🔈 PHP Internals News #18: – With Arnold Daniels about the Strict Operator Directive.

🛠 Tools

Symfony

Laravel

🌀 Async PHP

🚨 Security

💡 Misc

📺 Audio/Video

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, leave a comment or drop me a message on Twitter.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop


PHP Annotated – August 2019

$
0
0

php_annotated

Greetings everyone,

In our August edition of PHP Annotated, read about the future of PHP. Is it P++ or PHP2020? Get the latest on PHP 7.4.0 beta 2, Slim 4, and other releases. We cover Laracon US, as well as share other links for Laravel and Symfony, useful tools, videos, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • P++ – The controversy and accusations in PHP Internals over the removal of short tags <?, explicit call-site send-by-ref syntax, and other discussions eventually resulted in an unexpected proposal from Zeev Suraski – create a new PHP dialect. The working name P++ is not accidental here, as Zeev suggests creating a “sister” language, like C++ for C. PHP and P++ are supposed to be developed side by side within a single runtime.

    In the new P++ it will be possible to implement a lot of revolutionary improvements, to deprecate legacy, and clear things up without thinking about backward compatibility. Since the language would have new branding, it would not have this bad reputation. A “classic” PHP would get all the performance and other non-syntax features but maintain backward compatibility.

    The proposal received a lot of counterarguments, which Zeev tried to address on a page P++ idea: FAQ. The questions are quite serious though: limited team (just ~2 people working on PHP fulltime), possible community fragmentation, Hack’s experience, how PHP and P+++ code would really coexist and interact, and a lot more.

  • [RFC] Namespace-scoped declares, again – In the scope of this RFC, Nikita Popov formulates a more evolutionary approach to language development. In a nutshell, using optional directives like strict_types, for example.

    There are two possible ways of implementation: fine-grained – where individual changes are controlled by separate declare directives, and coarse-grained – when a bunch of features are combined into one directive as part of an “edition” such as “PHP 2020” for example. Similar to Editions in Rust.

  • Call for participation: Annotating internal function argument and return types – Ever wanted to become a PHP core contributor? You couldn’t think of a better time to start!
    Lack of type information for internal functions in Reflection is a long-standing issue. In PHP 8, all the necessary technical groundwork to support argument and return type annotations on internal functions at scale is already done. The only thing left is to add those type annotations to functions. This is something everyone can help with as it does not need expertise in C. Nikita has opened a sample PR to show the process: https://github.com/php/php-src/pull/4499.

🛠 Tools

  • krakjoe/tombs – A tool for locating dead code. You plug this in on production without the fear of performance overhead or any code modifications, wait for a day/week/month, and then look at the statistics to see which functions/methods have never been executed. Read more in Joe Watkins’ blog post.
  • krakjoe/stat – One more cool tool from Joe. This is an extension for profiling PHP applications in production which gives profiling info in a parallel thread. For more details, see this blog post.
  • nunomaduro/pest – A nice syntax sugar for PHPUnit that allows writing tests in facebook/jest style.
  • mpratt/Embera – An Oembed consumer library which gives you information about URLs. It helps you replace URLs to YouTube or Vimeo, for example, with their HTML embed code.
  • NxtLvLSoftware/php-static-constructors – Static constructors à la C#. They are executed automatically and not more than once.
  • exussum12/coverageChecker – The instrument helps you introduce good practices into your project gradually. For example, you can require 90% code coverage with tests, and not for the whole codebase at once, but just for the changed piece.
  • DaveLiddament/sarb – A similar tool that implements a Baseline feature for the quality analysis tools, which allows you to use them in legacy applications.

Symfony

Laravel

🌀 Async PHP

Serverless

💡 Misc

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, leave a comment or drop me a message on Twitter.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – September 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our September edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 1, Laravel 6, Monolog 2, and other releases. There are loads of insights from PHP Internals, including Union Types RFC, plus we’ll share links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

  • PHP 7.4.0 RC1 – The release-candidates cycle for the 7.4 branch has started now. At least 6 RCs are expected before the GA release.
  • PHP 7.1.32, PHP 7.2.22, PHP 7.3.9 – Security releases with fixes for critical vulnerabilities. All users are encouraged to update.
  • Monolog 2.0.0 – It’s been 4 years since it was first announced and now, finally, Monolog 2.0 is released. It requires PHP 7.2, uses type hints where possible and strict_types mode, and has new handlers (e.g. SqsHandler, TelegramBotHandler) and more. Support for Monolog 1.x will continue.

🐘 PHP Internals

  • Straw poll for P++ feasibility – Just in case you missed it, the P++ idea was rejected unanimously by the PHP community as completely unfeasible.
  • [PoC] throw_legacy_failure declare statement – An interesting pull request to PHP proof of concept for letting internal/old functions be able to throw an Exception in case of failure, instead of using the legacy behavior of returning null or false. This behavior is controlled using the declare statement: declare(throw_legacy_failure=1).
  • [RFC] Reclassifying engine warnings – Nikita Popov proposes taking a look at the existing warnings and notices in the engine, and thinking about whether their current classification is still appropriate: “Undefined variable” should be at least a Warning.
  • [RFC] Union Types v2 – Another epic proposal from Nikita continues on the work of Bob&Levi. It suggests adding union types in PHP 8. It would mean that any variable can be one of the specified types. You have been able to use union types in PHPDoc for a long time, but now they are will be checked.
    The proposed syntax T1|T2|... could be used anywhere you can use type declarations now:
    class Number {
        private int|float $number;
    
        public function setNumber(int|float $number): void {
            $this->number = $number;
        }
    
        public function getNumber(): int|float {
            return $this->number;
        }
    }

    Noteworthy, the RFC is published as a pull request to php/php-rfcs repo and anyone can comment or react with emojis. The final vote will still take place at wiki.php.net as before. According to Nikita’s message, this first experiment went well despite some noise in top-level comments, and the proposal received a lot of valuable feedback from the community.
  • In PHP 8 error_reporting will be E_ALL by default instead of the current:
    E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED.

🛠 Tools

Symfony

Laravel

  • Laravel 6 – A major framework update was announced at the Laracon EU conference. This is an LTS release and will get security updates for 3 years. Also, the framework follows Semver for release versions. It means that we will be seeing more first number increases, and version 7 will be released this coming winter. See what’s new in Laravel 6 at Laracasts.
  • facade/ignition – Among other things, Laravel 6 has a brand new error page. It is based on Whoops, but it provides more information and even allows you to fix some issues without ever leaving your browser.
  • Videos from Laracon US 2019
  • PHP Townhall #68: Behind the Facade – Matt Trask and Ben Edmunds are joined by Taylor Otwell to discuss what’s new with Laravel, the business side of things, and what it’s like organizing a huge conference.

🌀 Async PHP

💡 Misc

🔈 Podcasts

💬 Community

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, leave a comment or drop me a message on Twitter.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – October 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our October edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 3, GitHub dependency graph support for PHP, upgrading PSR standards, RFCs from PHP Internals, and the Coordinating PHP project. We’ll share links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Object Initializer – In this thorough document, the new syntax for quick object initialization has been proposed:
    class Car
    {
      public int $yearOfProduction;
      public string $vin;
    }
    
    $car = new Car {
      yearOfProduction = 2019,
      vin = "1FTFW1CVXAFD54385",
    };
    
    $car = new Car {
      yearOfProduction = 2019,
    }; // throws RuntimeException: Initialization of Car class object failed due to missing required properties
    Read about the proposal briefly in the author’s blogpost or listen to the podcast and take in all details in 🔈 PHP Internals News #30.
  • [RFC] Reclassifying engine warnings – Existing warnings and notices in the engine have been revisited, and according to the voting results we’ll have the following in PHP 8.0:
    • Undefined variables: now will throw a Warning.
    • Undefined array index: Warning.
    • Division by zero: will throw an Exception, and a new fdiv() function will be added which allows division by zero.
    • Invalid argument supplied for foreach(): Warning.
    All other changes passed the vote and were accepted.
    Find out more in the podcast 🔈 PHP Internals News #29 with Nikita Popov.
  • PHP project coordination – While Internals again stirred up quite a bit of drama, some good things also happened. Dan Ackroyd created a document, where he described all the current discussions and tasks. If you’d like to contribute to the PHP project, this can be a great starting point.

🛠 Tools

Symfony

Laravel

🌀 Async PHP

💡 Misc

🔈 Podcasts

💬 Community

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, leave a comment on this post or tweet me.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – November 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our November edition of PHP Annotated! Get the latest on PHP 7.4.0 RC 5, Xdebug 2.8.0, a critical vulnerability in PHP-FPM, and news from PHP Internals. There are also links for Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

🛠 Tools

Symfony

Laravel

Zend/Laminas

🌀 Async PHP

💡 Misc

🎥 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, leave a comment on this post or tweet me.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – December 2019

$
0
0

php_annotated

Greetings everyone,

It’s time for our December edition of PHP Annotated! Read about the latest releases PHP 7.4, Symfony 4.4 and 5.0, Xdebug 2.9, news from PHP Internals, articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Weak maps – PHP 7.4 has support for weak refs via the special class WeakReference. But in real-world applications, WeakMap is usually what developers would want to have. It is not possible to implement it with the current WeakReference, so this RFC proposes to add one.
    $map = new WeakMap();
            $obj = new stdClass();
            $map[$obj] = 42;
            var_dump($map);
            // object(WeakMap)#1 (1) {
            //   [0]=>
            //     ["key"] => object(stdClass)#2 (0) {}
            //     ["value"] => int(42)
            //   }
            // }
    
            // The object is destroyed here, and the key is automatically removed from the weak map.
            unset($obj);
            var_dump($map);
            // object(WeakMap)#1 (0) {
            // }
  • [RFC] Implement new DOM Living Standard APIs in ext/dom – Accepted unanimously.
  • [RFC] Union Types 2.0 – The proposal is accepted for PHP 8.0. The new syntax T1|T2|... can be used anywhere typing is allowed now: parameters, return types, properties.

🛠 Tools

  • Infection 0.15.0 – Update for mutation testing tool in PHP. In this release: Codeception support, PHP 7.4, Symfony 4.4 and 5.0, a couple of new mutators.
  • lisachenko/z-engine – An experimental library that allows accessing and modifying the internal structures of PHP itself, such as zend_class_entry, zval, etc., with the help of FFI. This makes it possible to do some incredible manipulations in runtime, for example, add an interface to an existing class, change the type of the object, or overload an operator.
  • krakjoe/ilimit – The extension provides a method to execute a call while imposing limits on the time and memory that the call may consume.
  • Twig 3.0The new version of the template engine has many small improvements, better performance, and cleaner code.
  • fzaninotto/Faker 1.9 – More than a hundred improvements in the tool for generating test data.
  • cekta/di – A decent PSR-11 implementation.
  • clue/phar-composer – Simple PHAR creation for every PHP project managed via Composer. Introductory post.
  • phplrt/phplrt – A tool for creating parsers in PHP by specified grammar. For example, json5 parser.

Symfony

Laravel

Zend/Laminas

  • Laminas transition update – The Apigility project will be renamed to Laminas API Tools (under Laminas\ApiTools namespace), and Expressive will become Mezzio. The official Laminas release is planned for January 2020.

Yii

🌀 Async PHP

💡 Misc

🎥 Videos

🔈 Podcasts

Give package developers support with symfony/thanks:

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post, or tweet me.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – January 2020

$
0
0

php_annotated

Greetings everyone,

It’s time for 2020’s first edition of PHP Annotated! This edition includes 4 new RFCs from PHP Internals and a few interesting updates for PHP 8 in pull-requests. We’ll catch up on the fresh releases from the end of 2019: Codeception 4.0, Phalcon 4.0, CakePHP 4.0. We’ve also got articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Weak maps – This proposal has been accepted and merged into the PHP 8 branch.
  • [RFC] Variable Syntax Tweaks – This RFC proposes to fix some inconsistencies related to dereferencing that were not addressed in PHP 7 in the scope of the Uniform Variable Syntax RFC.
  • [RFC] Static return type – The static keyword in the context of type declaration refers to the late static binding. This document proposes to allow using static for return-type declarations for methods. This can be useful for static constructors and fluent interfaces.
    class Test {
        public function doWhatever(): static {
            // Do whatever.
            return $this;
        }
    }
    For properties and method parameters, however, this does not make sense and will not work.
  • [RFC] Allow ::class on objects – There’s a proposal to allow getting a fully qualified name from the class instance $object::class in PHP 8, in a way similar to how it now works for classes Foo\Bar::class.
  • [RFC] “use global functions/consts” statement – If a function or constant is used without a prefix, PHP will try to find it first in the current namespace and then in the global one. The author proposes to add the statements use global function, and use global consts, which will make the interpreter look first globally for functions and constants without a prefix.

    A few changes are available as pull-requests:

  • [PR] Deprecate required param after optional – This one will make PHP throw a deprecation notice when there is an optional parameter before a required one in the function signature
    function test(FooBar $param = null, $param2)
    This made sense when there were no nullable types, back before PHP 7.2. But it can now be converted to function test(?FooBar $param, $param2).
  • [PR] Check abstract method signatures coming from traits – Signatures of abstract methods in traits are not validated with the ones implementing them, i.e. the following code now works without any errors:
    trait T {
        abstract function neededByTheTrait(int $a, string $b);
    }
    class C {
        use T;
        function neededByTheTrait(array $a, object $b) {}
    }

  • [PR] Ensure correct signatures for PHP magic methods – This pull request adds checks for magic methods signatures. At the moment, this only works as expected for __toString() and __clone(), and the following code, for example, does not show any error messages:
    class Foo {
    	function __get(int $name) {}
    }
    
    (new Foo)->{42};

  • [PR] Add Stringable interface – This PR introduces a new Stringable interface that ppl can declare when implementing __toString. The goal is to allow using the string|Stringable union type in PHP 8, to accept both strings and objects that implement __toString().

🛠 Tools

Symfony

Laravel

Zend/Laminas

Yii

🌀 Async PHP

  • 📺 Screencast on DriftPHP, the async PHP framework built on top of ReactPHP Symfony components.
  • amphp/http-client 4.0 – The updated HTTP client from Amphp now has full HTTP/2 support and many other improvements. Also, when running on PHP 7.4 you can install nghttp2, which will be used via FFI.

💡 Misc

📺 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post, or tweet me.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop

PHP Annotated – February 2020

$
0
0

php_annotated

Greetings everyone,

It’s time for the February edition of PHP Annotated! This edition includes 4 new RFCs from PHP Internals and research results on Generics in PHP. We also cover PHPUnit 9 and other releases, articles on Laravel and Symfony, useful tools, videos, podcasts, and a whole lot more!

⚡️ News & Releases

🐘 PHP Internals

  • [RFC] Allow function calls in constant expressions — In the current PHP versions, you can only use literals, and operations in constant expressions. This RFC proposes to allow global functions calls in constant declarations, default values of static properties, static variables, and default values of function parameters.
    class MyClass {
        const VALUES = [1, 0];
        const C1 = count(self::VALUES);
    
        public static $p = count(self::VALUES);
    
        public function foo($param = count(self::VALUES))
        {
            static $bar = count(self::VALUES);
        }
    }
  • [RFC] __toArray() — This onу proposes to add a new magic method __toArray(), which will work similarly to __toString(), i.e. will be called on explicit type casting to array, or when an object is passed as an argument to a function with an array parameter declaration, or when it’s returned from a function with its return type specified as an array.
    class Person
    {
        protected $name;
        protected $email;
        public function __toArray()
        {
            return [
                'name' => $this->name,
                'email'  => $this->email,
            ];
        }
    }
    
    $person = new Person('John Doe', 'j.doe@example.com');
    
    $personArray = (array) $person; // Calls __toArray()
    
    function foo(array $person) {
        var_dump($person); // Array here
    }
    
    function bar(Person $person): array {
        return $person;
    }
    
    var_dump(bar($person)); // and here it's an array
  • [RFC] Userspace operator overloading — The proposal to add operator overloading is still in draft status, but is actively discussed in Internals. Meanwhile, you can try operator overloading in PHP 7.4 with FFI based on lisachenko/z-engine.
  • [RFC] Validation for abstract trait methods — Currently, signatures of implementation for abstract methods from traits are not validated. For example, this code now works without errors:
    trait T {
        abstract public function test(int $x);
    }
    
    class C {
        use T;
    
        // It works now, but it shouldn't because of a type mismatch
        public function test(string $x) {}
    }

    It’s proposed to correct this behavior.
    The patch was published as a pull-request, but it contains a backward incompatibility, that requires to pass the RFC-process: if then current code has an incorrect implementation of the method from a trait, the proposed change will cause an error.
  • [RFC] Server-Side Request and Response Objects v2 — The RFC proposes to replace superglobal arrays such as $_GET, $_POST, $_SERVER, etc., with a ServerRequest class, and ServerResponse instead of header() calls and sending content.
  • Generics in PHP — Recently, Nikita Popov has been working on a study of the possibility of adding generics to PHP. In short, according to Nikita, there are some serious difficulties, and he is not sure yet if adding complete generics to PHP is a good idea.
    There is a pull request with a prototype implementation and all the problems and open questions are detailed here: https://github.com/PHPGenerics/php-generics-rfc/issues/45.
  • php/doc-en — English documentation is now editable via pull-requests on GitHub instead of old edit.php.net.

🛠 Tools

Symfony

Laravel

Zend/Laminas

🌀 Async PHP

💡 Misc

📺 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post, or tweet me.

Subscribe to PHP Annotated

Your JetBrains PhpStorm Team
The Drive to Develop


PHP Annotated – March 2020

$
0
0

php_annotated

Greetings everyone,

We’re pleased to present the March edition of PHP Annotated. It includes 4 new RFCs from PHP Internals, including Attributes v2 and a PHP language evolution proposal. It also covers Laravel 7, CodeIgniter 4, and other releases, as well as articles on Laravel and Symfony, useful tools, videos, podcasts, and plenty of other exciting posts!

⚡️ News & Releases

  • CodeIgniter 4.0 – After 5 years of development, a new version of the framework has been released. It’s been rewritten from scratch, and it works on PHP 7.2+ and implements PSR-1, 3, and 4.
  • PHP 7.4.3 – This release has a long-awaited fix for the opcache.preload_user bug, and preloading can now be used in production

🐘 PHP Internals

  • Accepted proposals: [RFC] Variable Syntax Tweaks, [RFC] Static return type, [RFC] Allow ::class on objects.
  • [RFC] Stringable – This proposal from Nicolas Grekas has also been accepted. In PHP 8, it will be possible to use the string|Stringable union type in places where a string is expected, and it will be possible to pass a class in them with the __toString() method.

    Interestingly, there’s no need to add implements Stringable explicitly, as this will be implemented automatically behind the scenes for all classes with __toString().

  • Language evolution – Nikita has started a discussion about how to keep PHP moving forward without breaking legacy code. One option is to introduce “editions,” similar to what Rust has, and declare them using per-file declares (for example, declare(edition=2020)).
  • [RFC] Write-Once Properties – This is a proposal to add a new property modifier that will allow you to initialize specific properties but disable their modification. There are several options for the name of the modifier: final, immutable, readonly, writeonce, locked, sealed.
    class Foo
    {
        <keyword> public int $a = 1;
        <keyword> public string $b;
        <keyword> public array $c = ["foo"];
        <keyword> public object $d;
    
        public function __construct()
        {
            $this->b = "foo";
        }
    }
    
    $foo = new Foo();
    
    $foo->a = 42;       // EXCEPTION: property a has already been initialized
    $foo->b = "bar";    // EXCEPTION: property b has already been initialized
    $foo->a++;          // EXCEPTION: incrementing/decrementing is forbidden
    unset($foo->c);     // EXCEPTION: unsetting is forbidden
    $foo->c[] = "bar";  // EXCEPTION: arrays can't be modified
    $var= &$this->c;    // EXCEPTION: reference isn't allowed
    
    $foo->d = new Foo();    // SUCCESS: property d hasn't been initialized before
    $foo->d->foo = "foo";   // SUCCESS: objects are still mutable internally

  • [RFC] Allow explicit call-site pass-by-reference annotation – This updated RFC suggests making it possible to explicitly indicate the passing of arguments by reference. This will warn a developer that the passed variable is going to change. It also proposes adding a directive to make the mode optional.
    declare(require_explicit_send_by_ref=1);
    
    function byRef(&$ref) {...}
    byRef(&$var);

  • [RFC] Increment/Decrement Fixes – In some cases, incremental and decremental operators do not behave in the same way that the explicit addition and subtraction of 1 with an assignment do. For example:
    <?php
    
    $a = [];
    $a = ++$a; // [] and no errors
    $a = $a + 1; // Fatal error

    It is proposed to fix inconsistencies in PHP 8 and throw an Error where appropriate.

  • [RFC] Attributes v2 – This is a second attempt to add full annotations in PHP with double bracket syntax <<...>>. There have been previous proposals for simple annotations and attributes, though the latter did not pass the voting.
    use Doctrine\ORM\Mapping as ORM;
    
    <<ORM\Entity(["repositoryClass" => UserRepository::class])>>
    <<ORM\Table("users")>>
    class User
    {
        <<ORM\Id, ORM\Column, ORM\GeneratedValue>>
        public int $id;
    
        <<ORM\Column(["unique" => true])>>
        public string $email;
    
        <<ORM\ManyToOne()>>
        public ?Address $address;
    }

  • [PR] Make sorting stable – The standard sorting functions in PHP are not stable. This means that the preservation of the original order of elements with the same values is not guaranteed. Here’s an example. There’s been a suggestion to fix this and make the sorting stable. However, with a large number of identical elements, such a fix would affect performance.

🛠 Tools

Symfony

Laravel

Yii

Zend/Laminas

🌀 Async PHP

💡 Misc

📺 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post, or send me a tweet.

Subscribe to PHP Annotated

Your JetBrains PhpStorm team
The Drive to Develop

PHP Annotated – April 2020

$
0
0

php_annotated

Greetings everyone,

This April edition of PHP Annotated overviews 10 new RFCs from PHP Internals, Composer 2.0 alpha, and other releases, as well as articles on Laravel and Symfony, best practices, useful tools, videos, and podcasts.

⚡️ News & Releases

  • PHP 7.4.5, PHP 7.3.17, and PHP 7.2.30 are released.
  • Composer v2.0 Alpha – April 5 marked exactly 9 years since the first commit to the Composer repository. You can now see what’s new and what has changed in the upcoming second major release. To try it right away, run: composer self-update --snapshot.
  • PhpStorm 2020.1 is out.

🐘 PHP Internals

  • The PHP 8 release schedule is available. The first alpha is expected on June 18, and the final release is planned for December 3.
  • [RFC] Constructor Property Promotion – Larry Garfield has published a detailed analysis of PHP’s object ergonomics. Larry concludes that it would be best to focus on these three RFCs: constructor promotion, named parameters, and compound Property Visibility.
    And in the wake of the analysis, this RFC proposes allowing you to declare properties directly in the constructor. Instead of writing this:
    class Point {
        public float $x;
        public float $y;
        public float $z;
    
        public function __construct(
            float $x = 0.0,
            float $y = 0.0,
            float $z = 0.0
        ) {
            $this->x = $x;
            $this->y = $y;
            $this->z = $z;
        }
    }
    It will be possible to use the following:
    class Point {
        public function __construct(
            public float $x = 0.0,
            public float $y = 0.0,
            public float $z = 0.0
        ) {}
    }
  • [RFC] Allow trailing comma in parameter list – There is also a proposal to allow a comma to be used after the last parameter in a function definition. This has already worked since PHP 7.3 for the list of arguments in a function call.
    class Uri {
        private function __construct(
            ?string $scheme,
            ?string $user,
            ...
            ?string $query,
            ?string $fragment // <-- ARGH!
        ) {
            ...
        }
    }
  • [RFC] Stricter type checks for arithmetic/bitwise operators – This RFC offers to generate a TypeError when an arithmetic or bitwise operator is applied to an array, resource, or object.
    var_dump([] % [42]);
    // int(0)
    // WTF?
  • [RFC] Type casting in array destructuring expressions – See an example:
    [(int) $now, (int) $future] = ["2020", "2021"];
    
    // The same as the following
    [$now, $future] = ["2020", "2021"];
    $now = (int) $now;
    $future = (int) $future;
  • [RFC] throw expression – This proposal has been accepted, and in PHP 8 throw will no longer be a statement. Rather it will be an expression. This means it will be possible to throw an exception in arrow functions, ternary operators, and other constructions.
    $callable = fn() => throw new Exception();
    
    $foo = $bar['key'] ?? throw new KeyNotSetOnBarException();
  • [RFC] Attributes v2 – The proposal to bring attributes (annotations) into PHP core by Benjamin Eberlei and Martin Schröder has been greatly improved.
    It looks like the proposal has a good chance to pass. The syntax is also being voted on: <<>> vs. @:.
    <<ExampleAttribute>>
    class Foo
    {
        <<ExampleAttribute>>
        public $x;
    
        <<ExampleAttribute>>
        public function foo(<<ExampleAttribute>> $bar) { }
    }
  • [RFC] Mixed Type v2 – At the moment, if a function does not have its return type specified, it is not clear whether the developer forgot to specify it or deliberately chose not to specify it for some reason. Besides, the mixed pseudotype is already used in the PHP manual.
    Máté Kocsis and Danack suggest adding it in the PHP 8. The mixed type will be equivalent to a union of array|bool|callable|int|float|null|object|resource|string types.
  • [RFC] non-capturing catches – This is a proposal to make a variable declaration optional in the catch block:
    try {
        changeImportantData();
    } catch (PermissionException) { // The intention is clear: exception details are irrelevant
        echo "You don't have permission to do this";
    }
  • [RFC] Match expression – Instead of fixing the switch construct Ilija Tovilo proposes to introduce a match expression, that is devoid of all the switch flaws, such as the absence of type checks and the possibility to return a value. It can also be extended to pattern-matching in the future.
    $expressionResult = match ($condition) {
        1, 2 => foo(),
        3, 4 => bar(),
        default => baz(),
    };
  • [RFC] Pipe Operator v2 – This is the second attempt to introduce the |> operator for sequential function calls while passing the result of the previous function as an argument to the next one.
    $result = "Hello World"
        |> 'htmlentities'
        |> 'explode'
        |> fn($x) => array_map(fn($v) => 'strtoupper', $x)
        |> fn($x) => array_filter(fn($v) => $v != 'O');
  • Rejected: Server-Side Request and Response Objects, Userspace operator overloading, Write-Once (readonly) Properties, Compact Object Property Assignment.

🛠 Tools

  • jlaswell/compote – A lightweight dependency management for PHP written in Go. It is not designed as a replacement for Composer but rather as a compliment for specific use-cases, CI for example. Currently, it can install locked dependencies and show locked dependencies for a project.
  • repman.io – A private PHP package repository manager for Composer.
    It also provides a proxy with CDN for packagist.org, which can speed up the download of packages.
  • dantleech/what-changed – A Composer plugin that generates change reports when you run composer update.
  • clue/graph-composer – This tool creates a graph of your project’s composer dependencies.
  • VKCOM/noverify v0.2.0 – A fast static analyzer written in Go for PHP. The release improves PHP 7 support, offers more diagnostics, and returns fewer false positives.
  • markrogoyski/math-php 1.0 – The first stable release of a math library for PHP.
  • ackintosh/ganesha 1.0 – A Circuit Breaker pattern implementation for PHP applications. Learn more in the blog post.
  • Spiral Framework – A high-performance hybrid PHP+Go framework.

Symfony

Laravel

Yii

Zend/Laminas

🌀 Async PHP

  • hyperf/hyperf – A framework for building microservices or middlewares based on Swoole coroutines.
  • clue/reactphp-flux – This package allows you to limit the number of simultaneously executed competitive tasks in ReactPHP.

💡 Misc

📺 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post or send me a tweet.

Subscribe to PHP Annotated

Stay safe!
Your JetBrains PhpStorm team
The Drive to Develop

PHP Annotated – June 2020

$
0
0

php_annotated

Greetings everyone,

Please welcome the June edition of PHP Annotated!
PHP internals have been very active and here are 3 accepted and 6 new RFCs, including alternative syntax for attributes — @@ and why #[] is better. There also has been some drama around renaming in the PHP world, and about PHP developers’ debugging practices. And as usual, a load of useful articles, tools, videos, podcasts, and more.

⚡️ News & Releases

🐘 PHP Internals

  • ✅ [RFC] Attribute Amendments — Attributes received a few additions: grouping capability <<Attr1, Attr2>>, renaming PhpAttribute to Attribute, validation, and the ability to add multiple identical attributes.
  • ✅ [RFC] Ensure correct signatures of magic methods — As for now, you can declare a magic method like this in a class:
    class Foo
    {
        function __get(int $name): void
        {
            echo $name;
        }
    }
    (new Foo)->{42};


    In PHP 8 however, signatures of magic methods will be validated and the code above will cause a compile-time error.

  • ✅ [RFC] Make sorting stable — All standard sort functions in PHP (sort, usort, asort, etc.) starting with PHP 8.0 will be stable. This means that the original element order with the same values is guaranteed. In current versions, it is easy to find examples where this is not the case.
  • [RFC] Opcache optimization without any caching — Declined.
  • [RFC] Make constructors and destructors return void — In current PHP versions, you can return any values from constructors and destructors, for example:
    class Test {
            public function __construct() {
                    return 0;
            }
    }
    
    $test = new Test();
    
    // this prints 0
    echo $test->__construct();


    Benas Seliuginas proposed to throw a Deprecated warning in such cases, and later in PHP 9.0 to remove this and generate a Fatal Error.

  • [RFC] Treat namespaced names as single token — Each element of the namespace is treated by the interpreter as a separate token. This is why there can be no keywords used in namespaces. For example, namespace app\function { class Foo {} }; will fail with a Parse Error. Nikita Popov proposed to consider the entire namespace as a single token as this would minimize backward compatibility problems when introducing new keywords.
  • [RFC] Rename T_PAAMAYIM_NEKUDOTAYIM to T_DOUBLE_COLON — The token :: in PHP is called T_PAAMAYIM_NEKUDOTAYIM — this fact was even pointed out as problem number one in the famous PHP Sadness list.
    George Peter Banyard and Kalle Sommer Nielsen suggested renaming it. We’re not sure this makes sense, as the error messages always note ::.
    Also, why remove a fun historical quirk?
  • [RFC] Shorter Attribute Syntax — Attributes have already been accepted for PHP 8, but many people do not like the syntax. Three options are being put to the vote: <<Attr>> (current) vs. @@Attr vs. #[Attr]. Brent Roоse had several convincing arguments for #[ ]:
    • It’s the same syntax as Rust, which is also a C-based language.
    • It’s compatible with old code: #[Attribute] will be just ignored by PHP <=7.4 as a comment.
    • @@ can be confused with the error suppress operator (example).
    • <<>> is also confusing, as it looks like bit-shift operators. In the future, it can be confused with generics that are likely to use the single angle brackets syntax <>.
    • In the meantime, @@ seems to be getting more votes.

  • [RFC] Change terminology to ExcludeList — The topic of renaming offensive terms has not been overlooked by the PHP world either. There have been heated discussions in the Internals.
    In the PHP core, the change affects only one thing: the configuration directive opcache.blacklist_filename should be renamed to opcache.exclude_list_filename.

    Many other PHP tools have already made changes in this regard: PHPUnit, Drupal, Xdebug, Yii, Composer (+ working with non-master Git branches).

    There is also a discussion on set of rules for PHP_CodeSniffer to find offensive words.

  • [RFC] Nullsafe operator — Instead of a bunch of nested conditions, Ilija Tovilo proposed to add the ability to refer to a property or method with a check for null:
    $country = $session?->user?->getAddress()?->country;

    Instead of

    $country =  null;
    
    if ($session !== null) {
        $user = $session->user;
    
        if ($user !== null) {
            $address = $user->getAddress();
    
            if ($address !== null) {
                $country = $address->country;
            }
        }
    }

  • PHP 8.0 release schedule was updated — The feature freeze has been moved to August 4, and the final release is scheduled for November 26.
  • You can try PHP 8 on 3v4l.org. Just check out the output in the php-master branch.

🛠 Tools

Symfony

Laravel

Yii

Zend/Laminas

🌀 Async PHP

💡 Misc

📺 Videos

🔈 Podcasts

Thanks for reading!

If you have any interesting or useful links to share via PHP Annotated, please leave a comment on this post or send me a tweet.

Subscribe to PHP Annotated

Your JetBrains PhpStorm team
The Drive to Develop

PHP Annotated Monthly – August 2018

$
0
0

PHP Annotated Monthly

Hello everyone! PHP Annotated Monthly is back in the game. This issue recaps news and notable materials of the last month. Read about PHP 7.3.0 Beta 3, Composer 1.7, and other releases, accepted PSR-17, Laravel Nova, an overview of Yii 3.0, a lot about async PHP including alternative Fiber API, security in PHP, a portion of useful tools, and many more!
(more…)

PHP Annotated Monthly – September 2018

$
0
0

PHP Annotated Monthly

Hello everyone! Please welcome September’s PHP Annotated Monthly with all the news and notable materials from last month.
Read about PHP 7.3.0 RC 2, Codeception 2.5, Laravel 5.7, Drupal 8.6 and other releases, HHVM ending support of PHP, typed properties in PHP, news from PHP Internals, async PHP, security in PHP, a portion of useful tools, and much more!
(more…)

PHP Annotated Monthly – November 2018

$
0
0

PHP Annotated Monthly

Hello everyone! Please welcome November’s PHP Annotated Monthly with all the news and notable materials from last month.
Read about PHP 7.3.0RC4, the future of PHP and Zend Framework, PSR-18 standard accepted, RFC from Internals on preloading files, Async PHP, a portion of useful tools, and a lot more!
(more…)

PHP Annotated Monthly – December 2018

$
0
0

PHP Annotated Monthly

Hello everyone,

Please welcome the last PHP Annotated Monthly this year with all the news and notable materials from the past month.
Read about PHP 7.3.0, end of life for PHP 5 and PHP 7.0, PHP on AWS Lambda, a bunch of new and accepted RFCs from Internals, Symfony 4.2, WordPress 5.0, Laravel WebSockets, many useful tools, and a lot more!
(more…)


PHP Annotated Monthly – January 2019

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome our first PHP Annotated Monthly of this year, with all the latest news and notable materials coming up from the world of PHP. Read all about the PHP updates, PHPStan, Psalm, Deployer, and other releases. There is news from PHP Internals, Laravel, Yii, and Symfony, some async PHP stuff, useful tools, and a whole lot more!
(more…)

PHP Annotated Monthly – February 2019

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome February edition PHP Annotated Monthly, with all the latest news and notable materials coming from the world of PHP. Read all about the PHP 8 development that’s underway, JIT in PHP, PSR-14 and PSR-12 in review, a bunch of new RFCs from PHP Internals, Laravel, Yii, Symfony, async PHP stuff, useful tools, and a whole lot more!
(more…)

PHP Annotated Monthly – March 2019

$
0
0

PHP Annotated Monthly

Greetings everyone,

Welcome to the March edition of PHP Annotated Monthly, with all the latest news and notable materials from the world of PHP. In today’s issue read all about the PHP updates, and 5 new and 3 accepted RFCs from PHP Internals. There is also news from Laravel, Symfony, some async PHP stuff, useful tools, and a whole lot more!
(more…)

PHP Annotated Monthly – May 2019

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome the May edition of PHP Annotated Monthly. Inside we have all the latest news and material from the world of PHP. Read all about the PHP updates, Codeception, WordPress, and other releases. PHP 7.4 is shaping up with a few new RFC proposals accepted including arrow functions, Zend Framework becomes Laminas, news from Laravel, Yii, and Symfony, some async PHP stuff, useful tools, and a whole lot more!
(more…)

PHP Annotated Monthly – June 2019

$
0
0

PHP Annotated Monthly

Greetings everyone,

Please welcome the June edition of PHP Annotated Monthly, with all the latest news and notable materials from the world of PHP. Read all about the PHP 7.4.0 alpha 1 release, Doctrine company, new and accepted proposals from PHP Internals, Laravel, Symfony, useful tools, and a whole lot more!
(more…)

Viewing all 104 articles
Browse latest View live