TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Classes: Function Usage (http://www.talkphp.com/advanced-php-programming/1838-classes-function-usage.html)

ReSpawN 01-01-2008 06:37 PM

Classes: Function Usage
 
I seem to have caught myself at the classes again. I've made a function called drawHeaders(); which is defined first, in the top of the function.

Now, inside a function called sendMail(); I want to call up the drawHeaders but all it gives me is a Fatal error: Call to undefined function drawHeaders()

drawHeaders gets, in a foreach loop, each header defined by the admin, and if defined by me in one of the documents (PHP), it foreach'es those as well and puts them into a variable which displays it correctly in the email's source.

Can you guys help me out?

TlcAndres 01-01-2008 06:39 PM

Can you show us the code in question? I'm horrible as imagining things.

Andrew 01-01-2008 06:54 PM

Well, if they are in the same class, are you using self::drawHeaders() or $this->drawHeaders()?

ReSpawN 01-01-2008 07:03 PM

O MY GOD. I was using the crappy cache of DreamWeaver again. I saved and SAVED and SAAAVED but nothing happened, so I though I was beginning to get completely retarted.

I tried $this->drawHeaders(); the first time. It didn't work (obviously cache) so I tried another one, and another one, and another one.

Anyways, it works now. Thanks for the simply and helpful post Andrew!

ReSpawN 01-02-2008 08:56 PM

Same problem again!

I've got 2 classes.

email.class.php
mysql.class.php

In mySQL class, I've got an error report to be send to an email address using the email class. So, normally in the source I would define $mail->sendQueryError(); but it doesn't work. Now i've got $mail = new EmailClass; and later on $mail->sendQueryError. So, $this-> doesn't work, and it doesn't get the headers since a function for retrieving those is already defined in the email.class.

The drawHeaders function in email.class.php
PHP Code:

function drawHeaders($reciever$additionalHeaders '') {
                foreach (
emailHeaders($reciever) as $headerKey => $headerValue) {
                    if (empty(
$headers)) {
                        
$headers $subheaderValue;
                    } else {
                        
$headers $headers.$subheaderValue;
                    }
                }
                if (
$additionalHeaders) {
                    foreach (
$additionalHeaders as $subheaderKey => $subheaderValue) {
                        if (empty(
$subheaders)) {
                            
$subheaders $subheaderValue;
                        } else {
                            
$subheaders $subheaders.$subheaderValue;
                        }
                    }
                }
                
                return (
$headers.$subheaders);
            } 

Part of the sendQueryError function inemail.class.php
PHP Code:

if (!empty($this->message)) {
                    
mail(    $this->reciever
                            
$this->subject
                            
$this->message
                            
$this->drawHeaders($this->reciever$this->addheaders), 
                            
$this->addparameters
                        
);        
                } 

Part of the mySQLQuery function in mysql.class.php
PHP Code:

if (!$this->queryResult) {
                        
$errorMessage  "<b>MySQL Retourneerde een Error.</b><br>";
                        
$errorMessage .= "<b>Error:</b> ".mysql_error()."<br>";
                        
$errorMessage .= "<b>Lijn:</b> ".$getLine."<br>";
                        
$errorMessage .= "<b>Bestand:</b> ".$getFile;
                        
$mail = new suRealityEmail;
                        
$mail->sendQueryError($errorMessage);
                        
$this->queryFailed++;
                    } 

And so, defined in index.php
PHP Code:

    require_once('includes/classes/mysql.class.php');
    require_once(
'includes/classes/email.class.php'); 


sjaq 01-03-2008 12:35 AM

What's the exact error message?

And you're using the function emailHeaders without $this in the drawHeaders function maybe that's the problem?

ReSpawN 01-03-2008 06:03 AM

Fatal error: Call to a member function sendQueryError() on a non-object in C:\wamp\www\suReality\includes\classes\mysql.class .php on line 130

Line 130 states; $mail->sendQueryError($errorMessage);
This is defined in the email.class.php as new suRealityEmail;, so it is ALWAYS defined when included/required.

$this-> didn't work either. $this-> returned;
Fatal error: Call to undefined method suRealityMySQL::sendQueryError() in C:\wamp\www\suReality\includes\classes\mysql.class .php on line 130

sendQueryError() is defined in the email.class.php, so it should be accessed since you use it in the SOURCE index.php, when BOTH are already included.

You see the problem?

sjaq 01-03-2008 04:36 PM

I don't really see the problem..

Can you upload the whole files for us to check them?

ReSpawN 01-03-2008 05:41 PM

I figured out the problem. I had to create another instance of suRealityEmail since I am using an OTHER classes function, in a class. So, new suRealityEmail worked fine.

Hopefully I won't need any more help on this subject, but still I thought it was weird.


All times are GMT. The time now is 10:04 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0