5

What is the official name for the php string type?

Is it 'string' like c#, or 'String' like Java, or either?

I could not find it in http://php.net/manual/en/language.types.string.php

I want to use it to strict type my function

function getImageName() : string;

or

function getImageName() : String;
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
mrwaim
  • 1,841
  • 3
  • 20
  • 29
  • 2
    https://mlocati.github.io/articles/php-type-hinting.html – René Höhle Mar 13 '19 at 20:41
  • 3
    The case does not matter. `STRING` works as well as `string` or `sTrInG`. But I'd always use the lower variant (`string`). This is the preferred way to dot it. – Sindhara Mar 13 '19 at 20:42
  • Interesting. I never knew PHP was case insensitive in some cases. https://stackoverflow.com/questions/33273941/php-case-sensitivity – mrwaim Mar 13 '19 at 20:47

1 Answers1

9

As PHP is a partially case sensitive language and, in particular, keywords are NOT case sensitive, the case doesn't matter for built-in type names. Both string and String will work as type declaration (aka 'type hint').

The official documentation mentions the lowercase variants, so it's probably a good idea to use lowercase keywords as code style — just like most PHP code styles use foreach and not Foreach, for example.

P.S. You can find the documentation on the PHP Function arguments page, 'Type declarations' section.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103