Skip to main content
expanded on the answer
Source Link
marco-fiset
  • 8.8k
  • 9
  • 38
  • 46

I think you are over-thinking your problem

In my opinion, dynamic typing is one of the features of PHP that makes it highly enjoyable to work with. Instead of enforcing strict typing rules, you can just document your function really well to indicate the parameters you expect. If the contract is not met, then results may vary and the fault is on the user of your function.

Plus if your code base is used only internally (by you and your team), you should have no problems with parameter types as you developped the code and should know how to use it. If your project is a library available to the public, good documentation is key. You should also have good unit tests to make sure your code behaves as expected and to provide examples on how to use your library.

I see you are trying to write Java code in PHP and that means that you still don't understand PHP well. When writing code in a given language, you should try to embrace the language features/philosophy instead of looking back to what you already know and trying to adapt.

In my opinion, dynamic typing is one of the features of PHP that makes it highly enjoyable to work with. Instead of enforcing strict typing rules, you can just document your function really well to indicate the parameters you expect. If the contract is not met, then results may vary and the fault is on the user of your function.

I see you are trying to write Java code in PHP and that means that you still don't understand PHP well. When writing code in a given language, you should try to embrace the language features/philosophy instead of looking back to what you already know and trying to adapt.

I think you are over-thinking your problem

In my opinion, dynamic typing is one of the features of PHP that makes it highly enjoyable to work with. Instead of enforcing strict typing rules, you can just document your function really well to indicate the parameters you expect. If the contract is not met, then results may vary and the fault is on the user of your function.

Plus if your code base is used only internally (by you and your team), you should have no problems with parameter types as you developped the code and should know how to use it. If your project is a library available to the public, good documentation is key. You should also have good unit tests to make sure your code behaves as expected and to provide examples on how to use your library.

I see you are trying to write Java code in PHP and that means that you still don't understand PHP well. When writing code in a given language, you should try to embrace the language features/philosophy instead of looking back to what you already know and trying to adapt.

Source Link
marco-fiset
  • 8.8k
  • 9
  • 38
  • 46

In my opinion, dynamic typing is one of the features of PHP that makes it highly enjoyable to work with. Instead of enforcing strict typing rules, you can just document your function really well to indicate the parameters you expect. If the contract is not met, then results may vary and the fault is on the user of your function.

I see you are trying to write Java code in PHP and that means that you still don't understand PHP well. When writing code in a given language, you should try to embrace the language features/philosophy instead of looking back to what you already know and trying to adapt.