PHP function param type best practices

前端 未结 3 573
梦毁少年i
梦毁少年i 2021-01-03 09:42

I am currently working on a framework and have come accros a snag... how should I handle incorrect parameter types when someone calls a function in the framework?

Ex

3条回答
  •  鱼传尺愫
    2021-01-03 09:45

    I would typecast the int and string datatypes automatically with no complaint (because they could be easy to mix up), but for something like a resource or object it could be a useful feature to notify the programmer of an error.

    I would also set up the notification code in its own function so things wouldn't get so repetitive. Anyways, Good luck!

提交回复
热议问题