12-28-2010, 08:10 AM
Aight', I've never dug deep into the php OOP thing, as I've always relied on procedural programming or OOP on a very low level...bla...bla...
Silly me,
ANYWAY, I've run into a problem, I just can't solve. I donno' whether I should use $this, parent, self, :: (Scope resolution operator). Or whether the static keywords is even supposed to be there.
The case is, that I have a main class, in which I've instantialized(?) two secondary classes (Main -> One and Main -> Two).
Afterwards, through the main class I've changed instance Two's variable $Xenon to be " in ". But I keep getting an:
- error.
Don't mind the resulting sentence, it's just random stuff
Main.php
child.php
child2.php
I've found out, that I can get the result I want if I pinpoint the $Xenon variable from an absolute/global perspective, like this:
But that kinda sucks, isn't there a relative way to do it? Like where you point to the parent and then point to subject from there? Hope you understand what I mean.
Regards and thanks in advance
- Vanilla
Silly me,
ANYWAY, I've run into a problem, I just can't solve. I donno' whether I should use $this, parent, self, :: (Scope resolution operator). Or whether the static keywords is even supposed to be there.
The case is, that I have a main class, in which I've instantialized(?) two secondary classes (Main -> One and Main -> Two).
Afterwards, through the main class I've changed instance Two's variable $Xenon to be " in ". But I keep getting an:
Code:
Trying to get property of non-object
Don't mind the resulting sentence, it's just random stuff
Main.php
PHP Code:
class Main
{
static public $One, $Two;
function Init()
{
require("child.php");
require("child2.php");
$this->One = new First;
$this->Two = new Second;
$this->Two->Xenon = " in ";
$this->One->Activate("the Oven");
}
}
$Main = new Main;
$Main->Init();
child.php
PHP Code:
class First extends Main
{
function Activate($Arg)
{
echo(Second::A().Second::$Xeen.$Two->Xenon.$Arg);
//Result i want: Mary's pet was burned in the oven
//Actual result: Mary's pet was burnedthe oven
}
}
child2.php
PHP Code:
class Second extends Main
{
static public $Xeen = " was burned";
static public $Xenon;
function A()
{
return("Mary's Pet");
}
}
I've found out, that I can get the result I want if I pinpoint the $Xenon variable from an absolute/global perspective, like this:
PHP Code:
function Activate($Arg)
{
global $Main;
echo(Second::A().Second::$Xeen.$Main->Two->Xenon.$Arg);
}
Regards and thanks in advance
- Vanilla