9 Nov 2007 16:21
Re: Getting "Trying to get property of non-object"
Thanks Guys, I really do appreciate the help.
I agree, I don't like leaving it like that. either.
I'm calling the $address object as follows:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
set_include_path( "/usr/include/php/ezcomponents-2007.1.1:" . ini_get( "include_path" ) );
require_once "Base/src/base.php"; // dependent on installation method, see below
function __autoload( $className )
{
ezcBase::autoload( $className );
}
class myConverter
{
public static function convertToUTF8IconvNoNotices( $text, $originalCharset )
{
if ( $originalCharset === 'unknown-8bit' || $originalCharset === 'x-user-defined' )
{
$originalCharset = "latin1";
}
return <at> iconv( $originalCharset, 'utf-8', $text );
}
}
$pop3 = new ezcMailPop3Transport( "mail.domain.com" );
$pop3->authenticate( "something-9IKiO1iGCm/QT0dZR+AlfA@public.gmane.org", "pass" );
$set = $pop3->fetchAll(true);
$parser = new ezcMailParser();
ezcMailCharsetConverter::setConvertMethod( array( 'myConverter', 'convertToUTF8IconvNoNotices' ) );
$mails = $parser->parseMail( $set );
//print_r($mail);
foreach ( $mails as $mail )
{
$from = formatAddress( $mail->from );
$to = formatToAddress( $mail->to );
// hack // some mail from users comes with FROM header blank but reply-to is populated (YUCK)
if ($from == "") $from = formatAddress( $mail->returnPath );
if ($to == "") $to = substr($mail->headers['Delivered-To'],2);
// end hack
// more code here
}
function formatAddress( $address )
{
return $address->email;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
So if I use the following, I should be ok.
function formatAddress( $address )
{
if($address instance of ezcMailAddress)
{
return $address->email;
}
}
I also have some USERS (not spam) that are sending messaged from phones where the FROM header is blank but reply-to is populated or sometimes the TO is not populated so I search the Delivered-To header. So I try to solve that by checking with the following:
if ($from == "" || is_null($from)) $from = formatAddress( $mail->returnPath );
if ($to == "" || is_null($from)) $to = substr($mail->headers['Delivered-To'],2); // this is the 1-user-9IKiO1iGCm/QT0dZR+AlfA@public.gmane.org address. so strip out the "1-"
I that the best way to handle that.
Thanks again guys. much appreciated. Thank you.
On Wednesday 07 November 2007 21:43:07 Dave Fischetti wrote:
Hey Gontran, Thanks for the reply.
I don't believe anything has changed. Since seeing this error. Though
I am on a Dedicated Virtual Server on Media Temple. They do
periodically update things. But my version of EZ has remained 2007.1.1
PHP 5 is running in CGI mode (I still have php 4 on the server
everywhere else. This is my only php5 script right now).
I guess I can live with the Notice, and just silence the PHP5 notices
display. I just thought I might have missed something.
The script is being called by a cron job:
/usr/bin/lynx -source http://www.domain.com/inbox.php5
I guess I could silence the cron so it doesnt reply at all (thats
where I'm seeing the errors. In my returned cron emails)
Thanks so much for the reply. Really appreciate it.
Fish
<>
On Nov 7, 2007, at 1:24 AM, Gontran Zepeda wrote:
In the interest of understanding your situation, please allow a
question or
few.
% On 2007-11-07 at 00:20:53 -0500, Dave Fischetti wrote:
I'm using the MAIL component in my application. All has been running
great, but recently started receiving this error sporadically when
parsing incoming mail in a mailbox.
<b>Notice</b>: Trying to get property of non-object in <b>/var/www/
vhosts/domain.com/httpdocs/inbox.php5</b> on line <b>684</b><br />
Has anything changed on your system relating to web services? Have
you
changed the version of Components that you are using? Which version
are
you using?
That line is this function:
function formatAddress( $address )
{
return "{$address->email}";
}
now I'm not sure what is causing it all of a sudden, but I am seeing
spam that sometimes comes into the account that has now FROM address,
but I haven't ensured that its happening when receiving those
messages.
Any help would be greatly appreciated.
Honestly, this seems like a harmless error message considering the
circumstance you explain. May I suggest modifying your php.ini
settings to
not output error level NOTICE warnings? I believe that may cure
what ails
your system.
Yours,
--
Gontran
% # E Pluribus Unix
% /usr/bin/fortune
BOFH Excuse #254:
Interference from lunar radiation
Hi Dave,
I just feel bad about ignoring the real cause of the problem. The code snippet
you sent is not enough to analyze the problem, because we don't see where and
how the $address object is created.
Instead of ignoring the notice, you could for example add sth. like:
if($address instance of ezcMailAddress)
{
return $address->email; // Why the { and " here?
}
return '';
But you should investigate, why you actually don't give an object to the
formatAddress function.
Hi,
As Dave said earlier, there are some spam messages with no From address.
In this case the $address which is passed to the formatAddress is null.
So as Thomas said, to avoid the notice you should check if $address is
an ezcMailAddress before returning its email property.
Cheers,
Alex.
--
Alexandru Stanoi
eZ Components System Developer
eZ Systems | http://ez.no
<div>
<div>Thanks Guys, I really do appreciate the help.</div>
<div><br class="webkit-block-placeholder"></div>
<div>I agree, I don't like leaving it like that. either. </div>
<div>I'm calling the $address object as follows:</div>
<div><br class="webkit-block-placeholder"></div>
<div>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div>
<div>
<div>set_include_path( "/usr/include/php/ezcomponents-2007.1.1:" . ini_get( "include_path" ) );</div>
<div>require_once "Base/src/base.php"; // dependent on installation method, see below</div>
<div>function __autoload( $className )</div>
<div>{</div>
<div> ezcBase::autoload( $className );</div>
<div>}</div>
<div><br class="webkit-block-placeholder"></div>
<div><br class="webkit-block-placeholder"></div>
<div>class myConverter</div>
<div>{</div>
<div> public static function convertToUTF8IconvNoNotices( $text, $originalCharset )</div>
<div> {</div>
<div> if ( $originalCharset === 'unknown-8bit' || $originalCharset === 'x-user-defined' )</div>
<div> {</div>
<div> $originalCharset = "latin1";</div>
<div> }</div>
<div> return <at> iconv( $originalCharset, 'utf-8', $text );</div>
<div> }</div>
<div>}</div>
<div><br class="webkit-block-placeholder"></div>
<div>$pop3 = new ezcMailPop3Transport( "mail.domain.com" );</div>
<div>$pop3->authenticate( "<a href="mailto:something@...">something@...</a>", "pass" );</div>
<div><br class="webkit-block-placeholder"></div>
<div>$set = $pop3->fetchAll(true);</div>
<div><br class="webkit-block-placeholder"></div>
<div>$parser = new ezcMailParser();</div>
<div>ezcMailCharsetConverter::setConvertMethod( array( 'myConverter', 'convertToUTF8IconvNoNotices' ) );</div>
<div><br class="webkit-block-placeholder"></div>
<div>$mails = $parser->parseMail( $set );</div>
<div><br class="webkit-block-placeholder"></div>
<div>//print_r($mail);</div>
<div><br class="webkit-block-placeholder"></div>
<div>foreach ( $mails as $mail )</div>
<div>{</div>
<div>
<span class="Apple-tab-span"> </span>$from = formatAddress( $mail->from );</div>
<div>
<span class="Apple-tab-span"> </span>$to = formatToAddress( $mail->to );</div>
<div>
<span class="Apple-tab-span"> </span>// hack // some mail from users comes with FROM header blank but reply-to is populated (YUCK)</div>
<div>
<span class="Apple-tab-span"> </span>if ($from == "") $from = formatAddress( $mail->returnPath );</div>
<div>
<span class="Apple-tab-span"> </span>if ($to == "") $to = substr($mail->headers['Delivered-To'],2);</div>
<div>
<span class="Apple-tab-span"> </span>// end hack</div>
<div><br class="webkit-block-placeholder"></div>
<div>
<span class="Apple-tab-span"> </span>// more code here<br class="webkit-block-placeholder">
</div>
<div>}</div>
<div><br class="webkit-block-placeholder"></div>
<div><br class="webkit-block-placeholder"></div>
<div>function formatAddress( $address )</div>
<div><div>
<div>{</div>
<div>
<span class="Apple-tab-span"> </span>return $address->email; </div>
<div>}</div>
</div></div>
<div><br class="webkit-block-placeholder"></div>
</div>
<div>
<div>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</div>
<div></div>
</div>
<div><br class="webkit-block-placeholder"></div>
<div>So if I use the following, I should be ok.</div>
<div>
<div><br></div>
<div>
<div>function formatAddress( $address )</div>
<div>{</div>
<div>
<span class="Apple-tab-span"> </span>if($address instance of ezcMailAddress)</div>
<div>
<span class="Apple-tab-span"> </span>{</div>
<div> <span class="Apple-tab-span"> </span>return $address->email;</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>}</div>
<div><br class="webkit-block-placeholder"></div>
<div><br class="webkit-block-placeholder"></div>
<div><br class="webkit-block-placeholder"></div>
<div>I also have some USERS (not spam) that are sending messaged from phones where the FROM header is blank but reply-to is populated or sometimes the TO is not populated so I search the Delivered-To header. So I try to solve that by checking with the following:</div>
<div><br class="webkit-block-placeholder"></div>
<div>
<div>if ($from == "" || is_null($from)) $from = formatAddress( $mail->returnPath );</div>
<div>if ($to == "" || is_null($from)) $to = substr($mail->headers['Delivered-To'],2); // this is the <a href="mailto:1-user@...">1-user@...</a> address. so strip out the "1-"</div>
</div>
<div><br class="webkit-block-placeholder"></div>
<div>I that the best way to handle that.</div>
<div><br class="webkit-block-placeholder"></div>
<div>Thanks again guys. much appreciated. Thank you.</div>
<div><br></div>
<div><br class="webkit-block-placeholder"></div>
<div><br class="webkit-block-placeholder"></div>
</div>
</div>
<div><br class="webkit-block-placeholder"></div>
<blockquote type="cite">On Wednesday 07 November 2007 21:43:07 Dave Fischetti wrote:<br>
</blockquote>
<blockquote type="cite"><blockquote type="cite">Hey Gontran, Thanks for the reply.<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">I don't believe anything has changed. Since seeing this error. Though<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">I am on a Dedicated Virtual Server on Media Temple. They do<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">periodically update things. But my version of EZ has remained 2007.1.1<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">PHP 5 is running in CGI mode (I still have php 4 on the server<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">everywhere else. This is my only php5 script right now).<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">I guess I can live with the Notice, and just silence the PHP5 notices<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">display. I just thought I might have missed something.<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">The script is being called by a cron job:<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">/usr/bin/lynx -source <a href="http://www.domain.com/inbox.php5">http://www.domain.com/inbox.php5</a><br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">I guess I could silence the cron so it doesnt reply at all (thats<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">where I'm seeing the errors. In my returned cron emails)<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">Thanks so much for the reply. Really appreciate it.<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">Fish<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><><br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite">On Nov 7, 2007, at 1:24 AM, Gontran Zepeda wrote:<br>
</blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">In the interest of understanding your situation, please allow a<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">question or<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">few.<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">% On 2007-11-07 at 00:20:53 -0500, Dave Fischetti wrote:<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">I'm using the MAIL component in my application. All has been running<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">great, but recently started receiving this error sporadically when<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">parsing incoming mail in a mailbox.<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><b>Notice</b>: Trying to get property of non-object in <b>/var/www/≤br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">vhosts/domain.com/httpdocs/inbox.php5</b> on line <b>684</b><br /><br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Has anything changed on your system relating to web services? Have<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">you<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">changed the version of Components that you are using? Which version<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">are<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">you using?<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">That line is this function:<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">function formatAddress( $address )<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">{<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"> return "{$address->email}";<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">}<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">now I'm not sure what is causing it all of a sudden, but I am seeing<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">spam that sometimes comes into the account that has now FROM address,<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">but I haven't ensured that its happening when receiving those<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">messages.<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Any help would be greatly appreciated.<br>
</blockquote></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Honestly, this seems like a harmless error message considering the<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">circumstance you explain. May I suggest modifying your php.ini<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">settings to<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">not output error level NOTICE warnings? I believe that may cure<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">what ails<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">your system.<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Yours,<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">--<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Gontran<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">% # E Pluribus Unix<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">% /usr/bin/fortune<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">BOFH Excuse #254:<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Interference from lunar radiation<br>
</blockquote></blockquote></blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite">Hi Dave,<br>
</blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite">I just feel bad about ignoring the real cause of the problem. The code snippet <br>
</blockquote>
<blockquote type="cite">you sent is not enough to analyze the problem, because we don't see where and <br>
</blockquote>
<blockquote type="cite">how the $address object is created.<br>
</blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite">Instead of ignoring the notice, you could for example add sth. like:<br>
</blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite">if($address instance of ezcMailAddress)<br>
</blockquote>
<blockquote type="cite">{<br>
</blockquote>
<blockquote type="cite"> return $address->email; // Why the { and " here?<br>
</blockquote>
<blockquote type="cite">}<br>
</blockquote>
<blockquote type="cite">return '';<br>
</blockquote>
<blockquote type="cite"><br></blockquote>
<blockquote type="cite">But you should investigate, why you actually don't give an object to the <br>
</blockquote>
<blockquote type="cite">formatAddress function.<br>
</blockquote>
<br>Hi,<br><br>As Dave said earlier, there are some spam messages with no From address. <br>In this case the $address which is passed to the formatAddress is null. <br>So as Thomas said, to avoid the notice you should check if $address is <br>an ezcMailAddress before returning its email property.<br><br>Cheers,<br>Alex.<br><br>-- <br>Alexandru Stanoi<br>eZ Components System Developer<br>eZ Systems | <a href="http://ez.no/">http://ez.no</a><br>
</div>
RSS Feed