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()
{
$newdb->two();
echo $id;
}

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

}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.