Skip to content
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

clarify classes named after internal php types #10403

Open
wants to merge 1 commit into
base: 1.11.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 ``open-resource|closed-resource`` (``open-resource`` has been added in 1.11.0) to avoid the name clash. ``number`` is an alias for ``int|float``, thus if you have a class ``Number``, you can annotate the ``int|float`` type to avoid the name clash. ``double`` and ``float`` are the same thing in PHP and both are allowed in annotations, so you can avoid name clashes by using the other. If you have both classes, you are out of luck.

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

Expand Down