i have two functions. In function two it has $id=9. how do i get function one to echo $id?

how do i adjust the below example to accomplish this?

$newdb = new Database();

class Database

function one()
echo $id;

function two() 
$id = 9
return $id;

7 Years
Discussion Span
Last Post by jkon

OK let’s take the entire OOP concept from the begging…
You declare $newdb = new Database(); so you have a new object…
You can do what ever you want with it …. Let’s say that you want to use void “one” of the object and that to use void “two” in order to set a variable and then “one” to echo it. So one will call with $this->two() the second function. But this is not enough. The main was just declaring the object. It didn’t called anything … $newdb = new Database(); And after that $newdb->one. The best way to go in OOP is throught C (and maybe COBOL and Python before that) and after that C++. Of course there is the shortcut of Java… In PHP OOP is originated syntax from C++ and is not a good strict paradigm. PHP is compiling to C so it is better to understand this family of languages first.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.