Jump to content

Archived

This topic is now archived and is closed to further replies.

roopurt18

Can't see global variable in member function?

Recommended Posts

I reinstalled XAMPP today on my development machine, set everything up and it works. Except now I have errors about a global error being undefined.

I have a global array defined in validate.php
[code]
  $g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';
[/code]

Then I have a CForm.php that defines a CForm object
[code]
  require_once('validate.php');
  
  class CForm{
    // ValidateForm
    // Do basic form validating, ensuring that all required fields in
    // $m_required are present, also ensure that all fields in $m_formats
    // match the required format
    // RETURN: true on success, false otherwise
    function ValidateForm(){
      global $g_pregs;

      // Next we check for specific formatting of the fields
      if( is_array( $this->m_formats ) ){
        foreach($this->m_formats as $format){
          if( !preg_match($g_pregs[$format[1]], $_POST[$format[0]]) ){
            // the format is invalid, add error message
            $this->AddError($format[2]);
            $this->AddErrorIndicator($format[0]);
          }
        }
      }
      /* More function code */
     return $value;
    }
  }
[/code]


The problem is now my $g_pregs is empty inside the CForm::ValidateForm method. I'm unsure why.

Share this post


Link to post
Share on other sites
/bump

Anyone? I can't develop my site and I have no idea why this is happening.

Share this post


Link to post
Share on other sites
included file needs php tags

[code]<?php
$g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';
?>[/code]

Share this post


Link to post
Share on other sites
It has them. This is a dev site that has always worked until I reinstalled XAMPP. I'm assuming a php setting was changed which is causing the problem. But I'm not sure what it is.

[!--quoteo(post=382459:date=Jun 11 2006, 03:54 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 11 2006, 03:54 AM) [snapback]382459[/snapback][/div][div class=\'quotemain\'][!--quotec--]
included file needs php tags

[code]<?php
$g_pregs['raidname'] = '/^[a-zA-Z0-9 ()]{1,32}$/';
  $g_pregs['charname'] = '/^[A-Z][a-z]{1,28}$/';
  $g_pregs['username'] = '/^[a-zA-Z0-9]{2,30}$/';
  $g_pregs['password'] = '/^[a-zA-Z0-9]{3,20}$/';
  $g_pregs['email'] = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+(\.[a-zA-Z]{2,4})+$/';
  $g_pregs['alpha'] = '/^[a-zA-Z]+$/';
  $g_pregs['digit'] = '/^[0-9]+$/';
?>[/code]
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.