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;
3

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.