You are here: Re: Strange warning when trying to create a class « PHP Programming Language « IT news, forums, messages
Re: Strange warning when trying to create a class

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация