Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is String an Object in PHP?

Tags:

php

Seeing other languages like Java or C++ String is an Object.
But in PHP is it the same thing ? Should I write string or String?
I know it may be a strange question but I can't find the answer even on php.net

Thank you very much.

like image 738
Shadowbob Avatar asked Mar 28 '13 16:03

Shadowbob


1 Answers

A String is not a Object in PHP by Default and casting is not required but it can be introduced if you want using scalar_objects

class StringHandler {

    public function length() {
        return strlen($this);
    }
}

register_primitive_type_handler('string', 'StringHandler');

So you can easily have

$str->length();
like image 168
Baba Avatar answered Nov 07 '22 02:11

Baba