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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.