Jump to content

Can't see global variable in member function?


roopurt18

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.
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.