Hi Erik,

You may want to re-investigate using nested functions for this purpose, it
seems a bit illogical.  The main reason is that it clutters up the source.
If you want a private function, use docblock tag @access private to let
other users know that it should not be accessed directly, or wait for php 5
when you can declare a method to be private/protected.

Having said that, if you are still into nested functions, try using

if (!method_exists($this,'isValidPhoneNumber'))
{
..
}

Greg

"Erik Price" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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: [EMAIL PROTECTED]
> jabber: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to