Implicit Type Conversion for PHP Classes?

前端 未结 7 1138
轻奢々
轻奢々 2021-01-25 06:16

Is there a way to tell the php complier that I want a specific implicit conversion from one type to another?

A simple example:

class Integer
{
  public $         


        
7条回答
  •  太阳男子
    2021-01-25 06:51

    PHP5 has type hinting, with limitations: http://ca2.php.net/manual/en/language.oop5.typehinting.php

    Specified types must be objects or array, so built in types such as string and int are not allowed.

    This is not a conversion, but will throw an error if an object of the specified type is not passed to the method or function, as in your example.

提交回复
热议问题