True statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

True statement

Post by John Cartwright »

Code: Select all

<?php
Keep in mind, you can do $myclass->email = $_POST['email']; or whatever you want to do with it. 

Let's run the email_check function inside the MyClass class.

$check_email = $myclass->check_email(); 

if(!$check_email){ 
    echo "The email address is not valid!"; 
} else { 
    echo "The email address is valid!"; 
} 
?>
This is from a tutorial I'm reading on classes and functions...
As I'm really trying to practice with this...

My question is this:

if (!$check_email)

This is checking to see if it's FALSE right?

Does register globals affect this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: True statement

Post by feyd »

My question is this:

if (!$check_email)

This is checking to see if it's FALSE right?

Does register globals affect this?
if $check_email is: 0, '', or unset will result in a false, IIRC..

register globals will not affect this because immediately before $check_email is set (most likely) from $myclass->check_email().. that is if check_email() returns anything...
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Code: Select all

$check_email = $myclass->check_email(); 

if(!$check_email){ 
    echo "The email address is not valid!"; 
} else { 
    echo "The email address is valid!"; 
}
just adding to what feyd is saying. Basically, the script you are using is just verifying that the email you sent to your class is indeed valid. So yeah, it's saying (If the email is NOT valid, then post the message "The email address is not valid!", otherwise, post "The email address is valid!").

this would be the same as using ! in post statements. ie :

Code: Select all

if(!isset($_POST['myformfield']))
{
   echo 'You must enter something in myformfield in order to continue...";
   exit;
}
// other code here, no need for an else statement as we are exiting the script upon failed attempt...
so, we just said "if the text box "myformfield" was left empty, then we need to tell the user about it.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

also heres another stupid question:

where does $this-> come from? why $this?

my educated guess is use $this is your function is not in a class?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Manual chapter
PHP Manual wrote: .......
Within a class definition, you do not know under which name the object will be accessible in your program: at the time the Cart class was written, it was unknown that the object will be named $cart or $another_cart later. Thus, you cannot write $cart->items within the Cart class itself. Instead, in order to be able to access it's own functions and variables from within a class, one can use the pseudo-variable $this which can be read as 'my own' or 'current object'. Thus, '$this->items[$artnr] += $num' can be read as 'add $num to the $artnr counter of my own items array' or 'add $num to the $artnr counter of the items array within the current object'.
.......
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thanks..... a have a journey a head of me upping my skills of php.. but im on my way :)
Post Reply