Skip to content

Returned matches for preg_match #40

Closed
@shish

Description

@shish

PHPStan has some Very Special Magic which allows the matches variable to be usefully-typed, but the magic isn't triggered by \Safe\preg_match

<?php

require_once "vendor/autoload.php";

// Dumped type: array{0?: string, 1?: non-empty-string}  
preg_match("/te(.)ting/", "testing patterns", $matches);
\PHPStan\dumpType($matches);

// Dumped type: array<string>|null                       
\Safe\preg_match("/te(.)ting/", "testing patterns", $matches);
\PHPStan\dumpType($matches);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions