Hello,
I'm not sure if this is the desired behavior and i don't want to submit
a bogus bug report.
class A
{
public function f1()
{
var_dump($this->_b);
}
}
class B
{
public $_b = 'stuff';
public function f2()
{
A::f1();
}
}
$b = new B();
$b->f2();
At first i would expect an error since A was not instantiated, at most i
would expect to return NULL
but not 'stuff'.
Is this a bug ?
I'm not sure if this is the desired behavior and i don't want to submit a bogus bug report.
…
At first i would expect an error since A was not instantiated, at most i would expect to return
NULL
but not 'stuff'.
Is this a bug ?
This is explained here: http://php.net/language.oop5.basic#example-155 (the paragraph after this example, and in example #2)
S
Hi,
Hello,
I'm not sure if this is the desired behavior and i don't want to submit a
bogus bug report.class A
{
public function f1()
{
var_dump($this->_b);
}
}class B
{
public $_b = 'stuff';public function f2()
{
A::f1();
}
}$b = new B();
$b->f2();At first i would expect an error since A was not instantiated, at most i
would expect to returnNULL
but not 'stuff'.
Is this a bug ?
Not really, it's a BC compatibility that we had to drag since PHP4. If
you enable E_STRICT, it should output a warning saying something like
"importing $this from invalid context". It is/was scheduled for
cleanup in the next major version.
Best,
--
--
Etienne Kneuss
http://www.colder.ch
Hello,
Thanks for the info, as pointed out by Sean Coates this is sort of
documented, I've submited a documentation (problem/)bug report.
https://bugs.php.net/bug.php?id=60499
E_STRICT
was disabled since a large part of the application was moved to
php 5 only last year and, even if i was aware that it is possible to
call non-static methods in a static way, i didn't expect this to work.
Hi,
Hello,
I'm not sure if this is the desired behavior and i don't want to submit a
bogus bug report.class A
{
public function f1()
{
var_dump($this->_b);
}
}class B
{
public $_b = 'stuff';public function f2() { A::f1(); }
}
$b = new B();
$b->f2();At first i would expect an error since A was not instantiated, at most i
would expect to returnNULL
but not 'stuff'.
Is this a bug ?
Not really, it's a BC compatibility that we had to drag since PHP4. If
you enable E_STRICT, it should output a warning saying something like
"importing $this from invalid context". It is/was scheduled for
cleanup in the next major version.Best,
--
--
Bezuz Bogdan
Programare Site
+40 721 269 934
bogdan.bezuz@emag.ro mailto:bogdan.bezuz@emag.ro
logo_emag
Dante International SA
Tel/Fax: +40 21 200 52 00/25
Swan Office Park, Windsor Building
Şos. Bucureşti Nord nr. 15-23
Bucureşti