|
Posted by Andy Jeffries on 03/09/06 15:21
On Wed, 08 Mar 2006 19:23:28 -0800, laredotornado@zipmail.com wrote:
> Using PHP 4, I'm trying to create a class, and I get warnings in my
> constructor function like the one below:
I'm guessing it's an easy one....
> Notice: Undefined variable: m_cat_to_buy in
> /usr/local/apache/htdocs/myfiles/dc_fns.php on line 72
m_cat_to_buy doesn't appear in your snippet of the class, so it's hard to
100% say, but there are some problems in your code that make it seem
likely that I know what you've done.
> class CProductForFree {
> var $m_cat_for_free = "";
Here you correctly declare a member variable m_cat_for_free
> function CProductForFree($p_cat_for_free, [snip])
> {
> $this->$m_cat_for_free = $p_cat_for_free;
Here you assign a passed in variable ($p_cat_for_free) to a dynamically
determined property which is not determined. An example would make this
clearer I'm sure:
You could have used
function CProductForFree($p_cat_for_free, [snip])
{
$property = "m_cat_for_free";
$this->$property = $p_cat_for_free;
But what you likely meant was:
function CProductForFree($p_cat_for_free, [snip])
{
$this->m_cat_for_free = $p_cat_for_free;
You create the member variable with "var $name" but you use it with
"$this->name" (notice no $ before name).
So, although you haven't included m_cat_to_buy in your code snippet, I'm
guessing it's the same problem as this.
Hope this helps.
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos
Navigation:
[Reply to this message]
|