Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to OOP
in general. I've spent the last three hours trying to figure out why this
code snipped doesn't do what I expect it to:
---snip---
<?php
$myTest = new Test;
echo $myTest->GetClassName; // Nada
class Test
{
// Class constructor
function Test()
{
// Empty on purpose...
}
// Returns class name
function GetClassName()
{
return "Test";
}
}
?>
---snip---
I would expect the "echo ..." line to display "Test", but it doesn't. I
swear I must be missing something really simple and really stupid, but I
can't find it for the life of me. Little help? Oh, PHP Version 4.3.4 if it
makes a difference.
Thanks in advance,
'Mutt 7 1705
"Shuttermutt" <an*******@nospam.net> wrote in message
news:Op*******************@twister.rdc-kc.rr.com... Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to
OOP in general. I've spent the last three hours trying to figure out why this code snipped doesn't do what I expect it to:
Try it the other way around.
<?php class Test {
// Class constructor function Test() { // Empty on purpose... }
// Returns class name function GetClassName() { return "Test"; }
}
$myTest = new Test;
echo $myTest->GetClassName; // Nada
?>
Note the class is b4 the calling of the class.
Simon.
Shuttermutt wrote: Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to OOP in general. I've spent the last three hours trying to figure out why this code snipped doesn't do what I expect it to:
---snip--- <?php
$myTest = new Test;
echo $myTest->GetClassName; // Nada
class Test {
// Class constructor function Test() { // Empty on purpose... }
// Returns class name function GetClassName() { return "Test"; }
}
?> ---snip---
I would expect the "echo ..." line to display "Test", but it doesn't. I swear I must be missing something really simple and really stupid, but I can't find it for the life of me. Little help? Oh, PHP Version 4.3.4 if it makes a difference.
Raise your error level, and you'll have the answer (which is quite
obvious BTW, but warnings may help spot less obvious bugs...)
Notice: Undefined property: GetClassName in <filename>.php on line 5
Ok, line 5 is :
echo $myTest->GetClassName; // Nada
Err... seems like parens are missings !-) Used to be a VB coder ?-)
Try this instead :
echo $myTest->GetClassName();
Thanks in advance,
You're welcome
MyOdd wrote: "Shuttermutt" <an*******@nospam.net> wrote in message news:Op*******************@twister.rdc-kc.rr.com...
Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to
OOP
in general. I've spent the last three hours trying to figure out why this code snipped doesn't do what I expect it to:
Try it the other way around.
<?php class Test {
// Class constructor function Test() { // Empty on purpose... }
// Returns class name function GetClassName() { return "Test"; }
}
$myTest = new Test;
echo $myTest->GetClassName; // Nada
?>
Note the class is b4 the calling of the class.
Err... The fact is that
- your code exhibits the same problem (you didn't tried your 'solution',
did you ?)
- the OP's code, once the *real* problem is corrected (see other post in
this thread), works quite ok.
BTW, I don't know much about the internals of PHP, but it seems that the
whole file is parsed before execution, so you don't need to put the
class definition *before* using it.
Bruno
$myTest = new Test;
echo $myTest->GetClassName; // Nada
?>
Note the class is b4 the calling of the class.
Err... The fact is that - your code exhibits the same problem (you didn't tried your 'solution', did you ?)
No, sorry.
- the OP's code, once the *real* problem is corrected (see other post in this thread), works quite ok.
Ideed. BTW, I don't know much about the internals of PHP, but it seems that the whole file is parsed before execution, so you don't need to put the class definition *before* using it.
Not for me, but i don't feel like looking into it.
Simon
Bruno Desthuilliers wrote: Err... seems like parens are missings !-) Used to be a VB coder ?-)
Try this instead : echo $myTest->GetClassName();
Thanks in advance, You're welcome
I am SUCH an idiot! Thank you.
--
'Mutt
Uzytkownik "Bruno Desthuilliers" <bd*****************@free.quelquepart.fr>
napisal w wiadomosci news:40*********************@news.free.fr... BTW, I don't know much about the internals of PHP, but it seems that the whole file is parsed before execution, so you don't need to put the class definition *before* using it.
No, in PHP class definition is a runtime operation. That's why something
like this works:
function define_cow($good) {
if($good) {
class Cow {
var $name;
var $weight;
}
}
else {
class Cow {
var $name;
var $madness_severity;
}
}
}
define_cow(false);
$obj = new Cow();
On Wed, 17 Mar 2004 12:30:16 +0100, Bruno Desthuilliers wrote: MyOdd wrote: BTW, I don't know much about the internals of PHP, but it seems that the whole file is parsed before execution, so you don't need to put the class definition *before* using it.
Bruno
That has changed as of PHP 5.
La'ie Techie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Howard |
last post by:
Hi,
in one of the recent posts, I saw someone pass two variables of built-in
type (int and double), by reference, to a member function of a class. That
function then took the addresses of those...
|
by: Eric Lilja |
last post by:
Hello, I have a class that I want to be able to output detailed information
about what it's doing either
to a file or to the screen. What I first tried was adding a
std::ostream-reference member...
|
by: Billy |
last post by:
Hi,
I would like to return a reference to a member variable:
class foo
{
int i;
int& geti() const;
};
|
by: Pekus Cons. e Desenvolvimento |
last post by:
Hi,
I have seen some developers commenting that a reference variable is 'more
garbage collection eligible' if the programmer set its value to null after
using it, like this:
public void...
|
by: z_learning_tester |
last post by:
I'm reading the MS press C# book and there seems to be a contradiction.
Please tell me which one is correct, 1 or 2.
Thanks!
Jeff
1. First it gives the code below saying that it prints 0 then...
|
by: Richard Lewis Haggard |
last post by:
Is it possible to put a reference to an object inside of a class? If so,
what is the syntax? The reason I want to do this is so that I can make a
copy of the original object, make modifications to...
|
by: Tim Clacy |
last post by:
1) Is this initialising the reference 'u' to the address of the literal '2'
or to the address 0x00000002?
unsigned const& u = 2;
2) What is the different between the initialisation of 'u'...
|
by: Bart Simpson |
last post by:
If a class has a member variable that is a reference. What happens to
teh class that is being referenced, when the containing class is destroyed?
e.g.
Class A{ };
Class B
{
B(const A&...
|
by: siddhu |
last post by:
If there is reference member variable in the class, why doesn't
default assignment operator work?
class A
{
int& i;
public:
A( int& ii):i(ii){}
//A& operator=(const A& a){i = a.i;}
};
|
by: Turin |
last post by:
Dear all;
As far as I understand the idea behind getter methods, it is used to
make sure that private memers of a class is returned appropriately to
the calling object.
However, if all I am...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |