shelluk Posted June 21, 2008 Share Posted June 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/ Share on other sites More sharing options...
Mattyspatty Posted June 21, 2008 Share Posted June 21, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-570937 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-570955 Share on other sites More sharing options...
Mattyspatty Posted June 21, 2008 Share Posted June 21, 2008 i didnt exaplin properly... $mxservers[$i] becomes an int, string or whatever type $pref is, this then means that $mxservers[$i]->host does not exist as it is not an object. Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-570957 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 I don't even see where he's assigning $mxservers to an object. And even if he did, it would have to be an array of objects for this to work. o_O Try my solution really quickly. Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-570966 Share on other sites More sharing options...
shelluk Posted June 21, 2008 Author Share Posted June 21, 2008 Thanks. Got it, as Darkwater said. $mxservers[$i] = array ($pref,$host); Was thinking the wrong way about it! Been a while since I've dabbled in all this. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-571015 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 =) Glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/111232-solved-help-with-quotattempt-to-assign-property-of-non-objectquot/#findComment-571017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.