TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Runtime Error (http://www.talkphp.com/absolute-beginners/1745-runtime-error.html)

obolus 12-15-2007 08:57 PM

Runtime Error
 
I was working on an OOP user tutorial and I've fixed everything so far except this:

Quote:

Runtime Notice on line 19,
Redefining already defined constructor for class mysql, in /xxx/xxx/xxx/classes/mysql.php
I'm thinking it's due to a class in my user.php class file that extends the SQL class defined in mysql.php, that also contains a __construct method.

First part of User class from user.php:

PHP Code:

class User extends mysql {
    
    var 
$mysql;

    function 
__construct( )     
    {
        
$this->mysql = new mysql();
        
        foreach(
$_POST as $key => $val
            {
                
$_POST[$key] = stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
                $
$key stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
            }
        
        
        foreach(
$_GET as $key => $val
            {
                
$_GET[$key] = stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
                $
$key stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
            }
        
        foreach(
$_SESSION as $key => $val)
            {
                
$_SESSION[$key] = stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
                $
$key stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
            }
        
        foreach(
$_COOKIE as $key => $val
            {
                
$_COOKIE[$key] = stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
                $
$key stripslashes(strip_tags(htmlspecialchars($valENT_QUOTES)));
            }
    } 


The first part of the code from the mysql class in mysql.php:

PHP Code:

class mysql {
    
    var 
$MYSQL_user DBUSER;
    var 
$MYSQL_pass DBPASS;
    var 
$MYSQL_host DBHOST;
    var 
$MYSQL_db DB;
    var 
$connect;
    var 
$get_db;

    function 
__construct() {
        
$this->Connect();
    }

    function 
mysql() {
        
$this->Connect();
    }

// Both of the functions above both call to a function called 'Connect', which is below.

    
function Connect( ) {

        
$this->connect mysql_connect($this->MYSQL_host$this->MYSQL_user$this->MYSQL_pass)or die(mysql_error( ));
        
$this->get_db mysql_select_db($this->MYSQL_db)or die(mysql_error().__LINE__.__FILE__);

    } 

Am I not even close with my assumption with regards to my guess on why this problem is occuring?

=o

thanks

SOCK 12-15-2007 09:13 PM

It's your mysql class constructor. Why are you using the traditional constructor type (the function named the same as the class) and the 'new' __construct() method? You have dual constructors.

ReSpawN 12-15-2007 09:40 PM

Redefining already defined [b]constructor[b] for class mysql
[b]constructor[b] __construct(or)

Like Sock said. :) What you should do, since you want to start TWO of them, is make two classes and engage BOTH with new classname; Then it engages both __constructors and then you're all free to go mind your business.

Hopefully that works. Or simply (if I am wrong), create a class with engages both classes it's functions.

$newclass = new classname;
classname { __constructor(); } started the two functions defined in the two other classes. Make sure BOTH other classes (2 and 3) do NOT contain the __construct magic function.


All times are GMT. The time now is 01:20 AM.

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