oop - Why Does PHP's Type Hinting Think My Class is a String? -
I've written that working on a PHP class. Type the method for an example of I am doing this: As I expected, get_class tells me that catcherable fatal error: 1 Domain \ Product :: setColour () to pass the domain Should be an example of \ color, string given, a ?? | Whatever you can think, it will be appreciated. I do a test, I do not see any problem: setColour () one of my class,
color .
$ color is an example of a
domain \ color , but I I can get an error when it
setColour () :
color looks like this:
color provides a custom
Enum type, which override
__ toString () , so I thought the problem might arise, but when I do not help in deleting
__ toString () implementation.
< Code> & lt ;? Php square color {Private $ name; Public Function __toString () {Return $ this- & gt; Name; } Public Function __ Composition ($ name) {$ this- & gt; Name = $ name; }} Class product {public $ color; Public function set color (color $ c) {$ this- & gt; Color = $ c; }} Error_reporting (E_ALL); $ Product = new product (); $ Color = new color ('red'); Echo get_class ($ color). ''; $ Product- & gt; SetColour ($ color); Echo $ product- & gt; Colour;
Comments
Post a Comment