OOP echoing out all...

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

User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: OOP echoing out all...

Post by Goofan »

ahh thanks that helped :D.
one question if ure not occupied :D
how can it be that if i set $cennection instead of $this->connection i get a error but "youre" way i didnt.. i would think its beicly the same thing.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: OOP echoing out all...

Post by AbraCadaver »

No, you need to read up on classes. Vars defined inside a function are destroyed when you exit the function. In a class, you set it as a class var if you need to access it later. It's the same thing with procedural programming. Check this:

Code: Select all

function foo() {
    $connection = mysql_connect('localhost', 'user', 'pass');
}
 
foo();
 
if($connection) {
    echo "CONNECTED";
} else {
    echo "NOT CONNECTED";
}
Notice: Undefined variable: connection in code on line 7
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: OOP echoing out all...

Post by Goofan »

ok i think i get it abit better will look into sessions more later thanks for all though.
Post Reply