Oops. Prematurely sent. Sorry about that.
As Rich said, NOTICE level warnings are usually logged when you're accessing a variable or an array index that doesn't exist yet.
Quote:
quote:
why do I get a parse error for this line ???
var $_oMail;
|
"var" is a keyword in PHP that declares member variables of a class, so it doesn't make sense to have "var $something" outside of a class definition.
If your declaration was actually INSIDE a class, for example:
class Foo
{
var $_oMail;
}
then look ABOVE the variable declaration line for some sort of syntax error (e.g. missing semicolon), because the PHP parser will choke on the next line when it can't figure out what the heck "var" is doing as part of the previous statement.
Moving on....
Quote:
quote:
and... why can't I find any documentation about this "=&" operator ???? what is it ?? what does it do ???
|
The =& operator has nothing to do with instantiating a class. It's actually TWO operators: = (assignment) and & (address of/reference).
So this line:
$this->_oMail =& Mail::factory("mail");
Is setting the _oMail member function of the $this instance of a class to be a reference to the return value of the function Mail::factory().
If you're unclear about references, what they are and how they work, let me know.
Moving on:
Quote:
quote:
OK its comparing the variable $bg and based on whether the result of strcmp is true or false assigns a new value. Well the problem is it doesn't exist anywhere to be compared!
!strcmp("FFFFFF", $bg) ? $bg = "F6F6F6" : $bg = "FFFFFF";
Its saying in English, if the $bg variable does not look like ffffff true make it f6f6f6 false make it ffffff. Which I'm scratching my head here to see how this makes sense! First the background variable isn't defined. And second if it does look like ffffff make it ffffff? Maybe they are trying to make a table with rows of alternating colour. That would be better done:
if ($i&1) $bg = "ffffff"; # if the count is odd...
else $bg = "f6f6f6"; # if the count is even...
|
You're right about it alternating the rows. strcmp() returns a negative number if the first string is less than the second, zero if they're equal, and a positive number if the first string is greater than the second. These comparisons are made using case-sensitive character matching; that is, a < b but a > Z.
The ! in front of the call to strcmp inverts the return value -- it makes a FALSE value TRUE and a TRUE value FALSE. In the context of integers, it turns NONZERO values into ZERO, and ZERO values to some NONZERO number (typically 1).
So: The statement actually reads in English as:
If $bg is "FFFFFF", set it to "F6F6F6", otherwise change it to "FFFFFF".
What's nice about the trinary operator (aka question-colon) is that you can express if-else expressions on a single line as a single statement. It's much cleaner, more concise, and readable (once you get the hang of it) than this:
if(!strcmp($bg, "FFFFFF"))
{
$bg = "F6F6F6";
}
else
{
$bg = "FFFFFF";
}
I do have a problem with the way the original statement was written. The whole point of using the trinary operator is to determine which value to assign to $bg. This should be rewritten as:
$bg = (!strcmp($bg, "FFFFFF"))? "F6F6F6" : "FFFFFF";
See how the assignment does NOT happen inside the case expressions? The case expressions are simply the resultant value of the trinary oprerator. There are no side effects (e.g. assignment) happening as the result the conditional expression. More plainly: The trinary operator should evaluate to a VALUE, just like the addition or subtraction operators.
Moving on.....
Quote:
quote:slightly edited for readability
I get this error:
Undefined variable: _oMail in /Library/WebServer/Documents/wrox_site/mail_test.php on line 10
with this script:
<?php
require_once("Mail.php");
require_once("DB.php");
function mailTest(){
echo "mailTest() called!";
$_oMail;
snip snip snip
}
but I don't get any errors regarding a missing include file, is this a PEAR problem!!!!! (sorry to kee banging on about it) I only ask because isError() is a method of the PEAR class, so maybe I'm not including the main pear class, and if I was all this would be sorted!!!!!
|
Okay, you see that line where you have $_oMail just sitting by itself? That's a valid statement. You're not DOING anything -- no assignments, function calls, sending output, etc... -- the statement simply evaluates to the value of $_oMail. It's just as if you had this code:
But guess what? You don't have $_oMail initialized anywhere; it doesn't exist before that line... so what do you get? An uninitialized variable warning.
Hope this helps clear some things up.
Take care,
Nik
http://www.bigaction.org/