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 setColour () one of my class, color .

I am doing this:

  $ color = new color ($ update-> color); Echo get_class ($ color); $ Product- & gt; SetColour ($ color);   

As I expected, get_class tells me that $ color is an example of a domain \ color , but I I can get an error when it setColour () :

catcherable fatal error: 1 Domain \ Product :: setColour () to pass the domain Should be an example of \ color, string given, a ?? |

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.

Whatever you can think, it will be appreciated.

I do a test, I do not see any problem:

 < 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

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -