Page 1 of 1

True statement

Posted: Sun Jun 13, 2004 11:13 pm
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?

Re: True statement

Posted: Sun Jun 13, 2004 11:17 pm
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...

Posted: Mon Jun 14, 2004 3:50 am
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.

Posted: Mon Jun 14, 2004 3:57 pm
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?

Posted: Mon Jun 14, 2004 4:02 pm
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'.
.......

Posted: Mon Jun 14, 2004 4:04 pm
by John Cartwright
Thanks..... a have a journey a head of me upping my skills of php.. but im on my way :)