Skip to content

Commit

Permalink
clarify classes named after internal php types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 8, 2024
1 parent 8bdb96f commit fc62281
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion website/src/writing-php-code/phpdocs-basics.md
Expand Up @@ -373,7 +373,7 @@ This is useful in the context of advanced types and [generics](/blog/generics-in
Classes named after internal PHP types
-----------------------------------------------------------

When having classes named like `Resource`, `Double`, `Number` (or `Mixed` until PHP 8), there is no possible way to distinguish between either the PHP internal type or the custom class to use in the PHPDoc. By default, PHPStan will consider the type as being the PHP internal type, which means some false-positives can appear.
When having classes named like `Resource`, `Double`, `Number` (or `Mixed` until PHP 8), there is no possible way to distinguish between either the PHP internal type or the custom class to use in the PHPDoc. If you want to reference the class, make sure to add the ``use`` statement or use the fully-qualified name.

```php
/**
Expand All @@ -391,6 +391,8 @@ To make PHPStan understand the passed argument must be an instance of a `Resourc
public function foo(Resource $var): void { ... }
```

If you want to reference an internal type but have such a class in the same namespace, you get the error ``Class {Namespace}\Resource referenced with incorrect case: {Namespace}\resource.``. For resources, you can use ``closed-resource`` (or since 1.11.0 ``open-resource``) to avoid the name clash.

Readonly properties
-------------------

Expand Down

0 comments on commit fc62281

Please sign in to comment.