PCP tells you exactly what is happening. Take a closer look at the logic of your code. Your class method defines a new bar function. Here you called it once - determined. Now you call it a second time - and again it tries to determine the function bar , which was already defined in the global scope at the previous call. So the error message is quite correct function should be defined only once. (for analogy, you can compare with the definition of constants)
To avoid such a situation, you need to check in one way or another whether a function has already been defined; the simplest thing here is to use function_exists()
class A { public function foo($x) { if(!function_exists('bar')){ function bar($n) { return $n * 2; } } return bar($x); } }
In this case, the method will be determined only at the first call.