Skip to content

Returned matches for preg_match #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shish opened this issue Feb 9, 2025 · 0 comments
Closed

Returned matches for preg_match #40

shish opened this issue Feb 9, 2025 · 0 comments

Comments

@shish
Copy link
Collaborator

shish commented Feb 9, 2025

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);
shish added a commit that referenced this issue Feb 9, 2025
shish added a commit that referenced this issue Feb 9, 2025
shish added a commit that referenced this issue Feb 9, 2025
shish added a commit that referenced this issue Feb 9, 2025
shish added a commit that referenced this issue Feb 9, 2025
@shish shish closed this as completed in 71cb3dc Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant