function getting redeclared
| From: | Erik Price | Date: | Tue, 18 Feb 2003 15:13:58 +0000 |
| Subject: | function getting redeclared | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-136016@lists.php.net to get a copy of this message | ||
Hi,
I have a problem where I am getting the following error, and I was wondering if anyone has seen this one before and can help me out.
"Fatal error: Cannot redeclare isvalidphonenumber() (previously declared in /home/bluekomo/public_html//classes/Registrant.class:360) in /home/bluekomo/public_html//classes/Registrant.class on line 360"
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? Here is the relevant section of code:
354 /**
355 * sets the phone property
356 */
357 function setPhone($phone) {
358 // TODO: determine if these formats are acceptable
359 // TODO: account for extensions (separate form field?)
360 function isValidPhoneNumber($num) {
361 $valid = false;
362 if (preg_match('!\d{9,9}!', $num)) {
363 $valid = true;
364 }
365 if (preg_match('!\(?\d\d\d\)?-?\s*\d\d\d-?\s*\d\d\d\d!',
366 $num)) {
367
368 $valid = true; 369 }370
371 return $valid; 372 }373
374 if (isValidPhoneNumber($phone)) {
375 $this->phone = $phone;
376 }
377 }
I am using PHP 4.3.0 on a RedHat machine with Apache 1.3.x.
Thanks for your help, it's been a while since I've used PHP!
Erik
--
Erik Price
email: erikprice@mac.com
jabber: erikprice@jabber.org