Declared a function with an int variable, passing in an int . The error falls out:

Catchable fatal error: Argument 1 passed to myTest () must

Why?

 myTest(intval(3)); function myTest(int $val){ } 
  • one
    type hinting only for objects, not for scalar types, i.e. php expects you to pass an int object (and not an int type). It’s written directly in the documentation: ΠšΠΎΠ½Ρ‚Ρ€ΠΎΠ»ΡŒ Ρ‚ΠΈΠΏΠ° Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ использован со скалярными Ρ‚ΠΈΠΏΠ°ΠΌΠΈ, Ρ‚Π°ΠΊΠΈΠΌΠΈ ΠΊΠ°ΠΊ int ΠΈΠ»ΠΈ string. РСсурсы ΠΈ Π’Ρ€Π΅ΠΉΡ‚Ρ‹ Ρ‚Π°ΠΊΠΆΠ΅ нСдопустимы. ΠšΠΎΠ½Ρ‚Ρ€ΠΎΠ»ΡŒ Ρ‚ΠΈΠΏΠ° Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ использован со скалярными Ρ‚ΠΈΠΏΠ°ΠΌΠΈ, Ρ‚Π°ΠΊΠΈΠΌΠΈ ΠΊΠ°ΠΊ int ΠΈΠ»ΠΈ string. РСсурсы ΠΈ Π’Ρ€Π΅ΠΉΡ‚Ρ‹ Ρ‚Π°ΠΊΠΆΠ΅ нСдопустимы. - BOPOH
  • From it that) Thank you! - mrFlyer
  • 3
    Well, or upgrade to php7, yes - u_mulder

1 answer 1

In php5. * Type hinting, in the function declaration, you can check only for an array or a specific class, scalar types are entered only in php7. * - http://php.net/manual/en/migration70.new-features.php