RE: [PHP] function getting redeclared
-Original Message- From: Erik Price [mailto:[EMAIL PROTECTED]] Sent: 18 February 2003 15:14 I have a script, registration.php, which calls require_once on the Registrant.class file mentioned in the above error message. The Registrant::setPhone() method is called more than once. Since it is called more than once, the function isValidPhoneNumber() defined within setPhone() is defined more than once, which I suspect is the source of the problem. Does PHP not allow you to define a function within a function and then call the enclosing function more than once? Well, it kinda does, but as it doesn't limit the scope in any way there's not really any point. Besides, it can lead to the kind of problems you're experiencing. Just declare the two functions sequentially in your include file. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function getting redeclared
On Tuesday, February 18, 2003, at 10:27 AM, Ford, Mike [LSS] wrote: I have a script, registration.php, which calls require_once on the Registrant.class file mentioned in the above error message. The Registrant::setPhone() method is called more than once. Since it is called more than once, the function isValidPhoneNumber() defined within setPhone() is defined more than once, which I suspect is the source of the problem. Does PHP not allow you to define a function within a function and then call the enclosing function more than once? Well, it kinda does, but as it doesn't limit the scope in any way there's not really any point. Besides, it can lead to the kind of problems you're experiencing. Just declare the two functions sequentially in your include file. Okay, so PHP stores all functions that are not class methods in a global namespace? Or does it even do this with methods? Just curious so I don't depend on anything I'm used to from other languages thanks! Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php