function (classname $arg) 

A function declared in this way will only accept an instance of the classname type as an argument, otherwise an exception will be thrown. But the built-in data types are not classes. From here two questions:

  • where the documentation highlights this feature;
  • whether it is possible to limit the type of the argument to the built-in data types directly when the function is declared.

    2 answers 2

    1. Found the same documentation .
    2. You cannot limit the argument to built-in types, except for an array.

      For primitive types - not. And you have an error (typo?): “Only an instance of class classname”. Not only. Correct "instance of type classname". There, after all, the interface name can be transferred.

      • I did not find documentation of this behavior, therefore I was mistaken. Poke, please, nose. - jfk
      • In php, starting with the 5th version, the OOP is quite tolerably implemented. Search now I will not do anything)) Google about polymorphism. I am sure you will find everything. - Vitaly Kustov
      • Not quite understand what the PLO is. But thanks anyway) - jfk
      • And I tell you: read about polymorphism. This is one of the basic principles of the PLO, which is implemented including. and through the transfer type of the object. - Vitaly Kustov
      • one
        I know and realize the basic principles of OOP. But I do not understand: how does polymorphism relate to the restriction of the type of argument when a function is declared? If you mean a crutch with converting standard types into classes, then the question was not about that. - jfk