Closed herndlm closed 3 years ago
Let's keep everything in issues.
:) Is callable-string
a Martin-invention?
PHPStan is a tool for OOP. Global function names are not supported as callable yet. There is an open issues for this.
In normal OOP world 'my-docs-function'
is [MyClass::class, 'myDocsFunction']
or [$this, 'myDocsFunction']
.
Please see this Symfony-inspired technology https://github.com/szepeviktor/Toolkit4WP/blob/43a015f3ee1fc06290fc7b894cdb95a740287f52/src/HookAnnotation.php#L20-L25
my-docs-function
isn't a valid function name so it's not a valid callable. Should it be my_docs_function
?
callable-string
is real :)
And yeah this was an invalid example, sorry. Was reported by a colleague and the default value of '' is also is not accepted. Not a 100% sure if it would accept valid function names, but I think it doesn't
I prefer real callables but I think that's not the WP way, right?
If you pass a valid callback function name to that parameter there should not be an error. What's the actual value you're passing? Is it the string name of a function that exists? my_function
is a valid callable as long as that a function with that name exists. OOP has nothing to do with it.
OK, thx. It's only about the default value of '' then. Which cannot be specified in case one of the later args needs to be set.
Ah yes the default value of ''
is a known issue, it should be nullable instead. I think that's covered in one of the PHPStan tickets for WordPress core, maybe https://core.trac.wordpress.org/ticket/52217
Thx for the insights! That's enough for me :)
Is this a problem we can fix? Looks like it's coming from the stubs / wordpress docs, but actually it is supposed to be used with callable strings, right? E.g. as in
phpstan reports
I guess many many more functions are having the same problems?
This is more like a discussion, @szepeviktor want to enable the discussions feature in this repo? ;)