Jump to content

[SOLVED] Help with "Attempt to assign property of non-object"


shelluk

Recommended Posts

The line "$mxservers[$i]->host = $host;" in the following code gives me the error "Warning: Attempt to assign property of non-object in /path/to/file line xx"

 

	require 'Net/DNS.php'; 
	$D = new net_dns(); 
	$result = $D->resolver->query('gmail.com','mx'); 	

	for ($i = 0; $result->answer[$i]; $i++) {
		$host = $result->answer[$i]->exchange;
		$pref = $result->answer[$i]->preference;
		$mxservers[$i] = $pref;
		$mxservers[$i]->host = $host;
	}

 

Any help appreciated. I bet it's something stupid too!

 

Thanks,

Shell

this is an error of trying to assign a property of an object that does not exist (as the error suggests)

 

assuming the error is on this page (without page name and line numbers its hard to tell).

$mxservers[$i] = $pref;
$mxservers[$i]->host = $host;

this is the probably problem, because $pref is not an object/class and $mxservers will become the same type as $pref. (string, int etc.)

 

 

perhaps you intended this:

$mxservers[$i]->pref = $pref;
$mxservers[$i]->host = $host;

You were close, Matty, but you chose the wrong one. =P  The error is coming from the second one, because $mxrecords isn't an object, therefore it has no properties that you can assign values to.  You can overwrite objects with strings all you want, that won't error you out.  But an array has no properties.  I'm pretty sure he wanted to make a multidimensional array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.