enveetee Posted December 2, 2015 Share Posted December 2, 2015 I have several scripts which contain the exact same function name and accept the same number of arguments example script1.php <?php function DoThis($arg1){ . . } ?> script2.php <?php function DoThis($arg1){ . . } ?> script3.php <?php function DoThis($arg1){ . . } ?> What syntax should I use (if indeed i can) to call each one. Is it something to do with NAMESPACE? Thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 2, 2015 Share Posted December 2, 2015 Yes you would have use namespaces but why would you define three functions with the same name? Whats is the differences between them? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 2, 2015 Share Posted December 2, 2015 Why namespaces? Each script has its own scope, so if you call it with, say DoThis('Hello world'); then it will call the version that is defined in the same script Quote Link to comment Share on other sites More sharing options...
requinix Posted December 2, 2015 Share Posted December 2, 2015 Why namespaces? Each script has its own scope, so if you call it with, say DoThis('Hello world');then it will call the version that is defined in the same script It sounds like OP wants to call all three functions. Not just one of them. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 2, 2015 Share Posted December 2, 2015 assuming @requinix is correct, I would say: Three functions that take the same parameters and do the same thing = two functions too many. Three functions that take the same parameters but do different things = three different functions that should have three unique names. Three functions that take the same parameters and do the same thing, but depend on context = use namespaces. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.