I recently came across a weird piece of code
if(foo == bar){
function foo_bar(){
// Function definition
}
}
Is this a good practice of coding ?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityI recently came across a weird piece of code
if(foo == bar){
function foo_bar(){
// Function definition
}
}
Is this a good practice of coding ?
There is one valid use case:
if( !function_exists("helloWorld") ) {
function helloWorld() {
...
}
}
Other than that, it would be preferable to avoid defining your functions inside if blocks.