Page 1 of 1

[solved]Notice: Undefined property error

Posted: Tue May 22, 2007 4:01 am
by mcccy005
ALrighty I've been scratching my brain for nearly an hour on this ridiculous error.

The error I get is as follows:
Notice: Undefined property: sql_query_value::$get_field_name in S:\Web_Pages\Object_Library\Input_Set\sql_query.php on line 24

For some reason I can call this get_field_value method of an sql_query_value object from the first class; but when I parse this object to the sql_query class, it won't call the method then???

Code: Select all

$field_one = new sql_query_value("region_name", "WOOOOHOOOO");
$field_two = new sql_query_value("state", "SA");
$fields=array($field_one, $field_two);
echo "field_one=".$fields[1]->get_field_value( ); //THIS LINE WORKS FINE
$region_info_query = new sql_query("regions", $fields);

class sql_query_value
{

	private $field_name,	//Stores the namem of the column in the database with which the field_value will be stored in
	$field_value;	//Stores the value (or data) which is to be inserted into the database
	
	//Constructor - creates a new sql_query_value object
	public function __construct($field_name, $field_value)
	{
		$this->field_name=$field_name;
		$this->field_value=$field_value;	
	}
	
	//Returns the field name of this object
	public function get_field_name( )
	{
		return $this->field_name;	
	}
	
	//Returns the field value of this object
	public function get_field_value( )
	{
		return $this->field_value;
	}

}

class sql_query
{
	private $table_name,	//stores the name of theh table which the data will be entered into
			$sql_query_values;	//stores an array of sql_query_values
	
	public function __construct($table_name, $sql_query_values)
	{
		$this->table_name=$table_name;
		$this->sql_query_values=$sql_query_values;

//LINE 24		echo "tester".$sql_query_values[0]->get_field_value;
	}
}

Posted: Tue May 22, 2007 4:11 am
by volka
Php tells you that there is no property get_field_name. You want to call a method.
$object->property , $object->method()

Posted: Tue May 22, 2007 4:40 am
by mcccy005
Yeah sorry - got the errors etc. mixed around whilst putting the post up.

It comes up with basically the same error for get_field_name( ) AND get_field_value( ) when I call it from within sql_query_value after I parse it to the constructor; but it works fine when I first create the sql_query_value object.

Posted: Tue May 22, 2007 4:44 am
by mcccy005
Woops - I thought you were getting at something there.
For nearly one ****** hour, I spent looking at such a small amount of code and I forgot to add the "( )" to the end of it.

Time for a coffee!!


Many many thanks.

Posted: Tue May 22, 2007 4:47 am
by volka
mcccy005 wrote:It comes up with basically the same error
Very unlikely. Please post the exact error message you get for

Code: Select all

echo "tester".$sql_query_values[0]->get_field_value();