ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-general
php-general
Re: [PHP] learning classes not sure how to do this correctly
by Jochem Maas other posts by this author
Dec 14 2006 8:52AM messages near this date
[PHP] learning classes not sure how to do this correctly | [PHP] Re: Error Display
macha@[...].com wrote:
>  just starting to get used to classes, trying to figure out what i am
>  doing wrong, i know its going to be something stupid on my part,
>  probably really shouldn't be using a if statement or something heh
>  
>  just doing a basic email verification to make sure its looks like email
>  addy
>  
>  so i take the post to a var
>  
>  PHP Code:
>  $email_address = $_POST['email_address'];
>  
>  
>  run it through this function in my class
>  
>  PHP Code:
>  function check_email($address){
>          if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+.[a-zA-Z0-9\-\.]+$',
>  $address))

please consider using the preg_*() functions instead of the posix based
regexp funcs; read here to get a feel of why the preg_*() funcs are 'better':

	http://php.net/manual/en/ref.regex.php

also you could shorten the function a little like so;

function check_email($address) {
	return (boolean) ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+.[a-zA-Z0-9\-\.]+$',$address);
}

>              return true;
>          else
>              return false;
>      }
>  
>  
>  and then if true i want it to continue on with the script or error out
>  and quit back to the other page and display the error. so i have tried
>  something like this and stuff similar but get a error
>  Fatal error: Call to a member function on a non-object in

$keclass is not an object. you need to do something like this
before you use $keclass (where 'YourClass' is the name of your class):

$keclass = new YourClass;

>  
>  PHP Code:
>  if (!$keclass->check_email($email_address)) {
>      $keclass->seterr(555);
>      include('test.php');
>      exit();
>  }
>  
>  $keclass->seterr(000);
>  include('test.php');
>  exit();
>  
>  
>  the seterr is just a simple thing that takes the number and puts in a
>  session var for latter display...
>  

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

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved