Hi All,
<?php
class Foo {
const HELLO = "con\n";
function memberfunc() {
echo HELLO; //does not work
echo Foo::HELLO; //works
}
}
$obj = new Foo();
$obj->memberfunc();
?>
With a error_reporting=2047 I get
Notice: Use of undefined constant HELLO - assumed 'HELLO' in
/rekha/php-5.0.0/test.php on line 5
Whey echo HELLO fails?
With regards
Kamesh Jayachandran
Hi Kamesh,
Try replacing Foo::HELLO with self::HELLO. This should work.
(this is documented, the manual will reflect it in the next build)
didou
Kamesh Jayachandran wrote:
Hi All,
<?php
class Foo {
const HELLO = "con\n";
function memberfunc() {
echo HELLO; //does not work
echo Foo::HELLO; //works
}
}
$obj = new Foo();
$obj->memberfunc();
?>With a error_reporting=2047 I get
Notice: Use of undefined constant HELLO - assumed 'HELLO' in
/rekha/php-5.0.0/test.php on line 5
Whey echo HELLO fails?With regards
Kamesh Jayachandran
Hi Mehdi,
Even Foo::HELLO works.
My question is why simple HELLO inside a member function does not work.
Why are we not able to access the static and const members of a class
from inside a class member function like the way with other member
variables.?
Any special reasons.
With regards
Kamesh Jayachandran
On Wed, 28 Jul 2004 18:10:52 +0200, "Mehdi Achour" didou@php.net said:
Hi Kamesh,
Try replacing Foo::HELLO with self::HELLO. This should work.
(this is documented, the manual will reflect it in the next build)didou
Kamesh Jayachandran wrote:
Hi All,
<?php
class Foo {
const HELLO = "con\n";
function memberfunc() {
echo HELLO; //does not work
echo Foo::HELLO; //works
}
}
$obj = new Foo();
$obj->memberfunc();
?>With a error_reporting=2047 I get
Notice: Use of undefined constant HELLO - assumed 'HELLO' in
/rekha/php-5.0.0/test.php on line 5
Whey echo HELLO fails?With regards
Kamesh Jayachandran
Hi Mehdi,
Even Foo::HELLO works.
My question is why simple HELLO inside a member function does not work.Why are we not able to access the static and const members of a class
from inside a class member function like the way with other member
variables.?
Other member variables don't work either like this, you need to specify
$this-> always.
Derick
Hi Derick,
Thanks for the correction.
With regards
Kamesh Jayachandran
On Mon, 2 Aug 2004 16:02:23 +0200 (CEST), "Derick Rethans"
derick@php.net said:
Hi Mehdi,
Even Foo::HELLO works.
My question is why simple HELLO inside a member function does not work.Why are we not able to access the static and const members of a class
from inside a class member function like the way with other member
variables.?Other member variables don't work either like this, you need to specify
$this-> always.Derick