String type casing in php, is it string or String?
Asked Answered
M

1

6

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;
Mascagni answered 13/3, 2019 at 20:37 Comment(3)
mlocati.github.io/articles/php-type-hinting.htmlAmendatory
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.Bagging
Interesting. I never knew PHP was case insensitive in some cases. https://mcmap.net/q/324905/-php-amp-case-sensitivity-duplicateMascagni
H
10

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.

Heartland answered 13/3, 2019 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.