You could check if a variable in $this exists:
class A
{
var $bla;
function Go()
{
switch(isset($this->bla))
{
case true: echo 'Called Dynamicaly<br />'; break;
case true: echo 'Called Statically<br />'; break;
}
}
}
Or, if that doesn't work, you could do this:
class A
{
var $dynamic = true;
function Go()
{
switch(isset($this->bla) && $this->bla == true)
{
case true: echo 'Called Dynamicaly<br />'; break;
case true: echo 'Called Statically<br />'; break;
}
}
}
Or:
class A
{
var $dynamic;
function A()
{
$this->dynamic = true;
}
function Go()
{
switch(isset($this->bla) && $this->bla == true)
{
case true: echo 'Called Dynamicaly<br />'; break;
case true: echo 'Called Statically<br />'; break;
}
}
}
Just some things you could try.
"Sean Malloy" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Consider the following code...
>
> class A
> {
> function Go()
> {
> switch (isset($this))
> {
> case true: echo 'Called Dynamically<br />'; break;
> case false: echo 'Called Statically<br />'; break;
> }
> }
> }
>
> class B
> {
> function Go()
> {
> A::Go();
> }
> }
>
> A::Go();
> $a = new A();
> $a->Go();
>
> B::Go();
> $b = new B();
> $b->Go();
>
>
> My understanding is that the output should be:
>
> Called Statically
> Called Dynamically
> Called Statically
> Called Statically
>
> Yet the output is actually:
>
> Called Statically
> Called Dynamically
> Called Statically
> Called Dynamically
>
>
> Now my question is, is this what was intended?
>
> It seems that if you call a static class from within a dynamic instance of
a
> class, the static class then decides $this should reference the class from
> which the static class was called
>
> Anyone else come across this?
>
> It could be useful, but right now, its bloody annoying! I need a class to
be
> called from within another clas, and it needs to know wether it has had an
> instance created, or wether it is being statically called, and now I'll
have
> to write some kludge code instead...
>
>
>
>
> ///////////////////////////////////////////////////////////////////
> // Sean Malloy
> // Developer
> // element
> // t: +61 3 9510 7777
> // f: +61 3 9510 7755
> // m: 0413 383 683
> ///////////////////////////////////////////////////////////////////
>
> DISCLAIMER:
> � copyright protected element digital pty ltd 2002.
> the information contained herein is the intellectual property
> of element digital pty ltd and may contain confidential material.
> you must not disclose, reproduce, copy, or use this information
> in any way unless authorised by element digital pty ltd in writing
> or except as permitted by any applicable laws including the
> copyright act 1968 (cth).
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php