re:re:[PHP]

From: Date: Sun, 10 Oct 2004 07:02:50 +0000
Subject: re:re:[PHP]
Groups: php.general 
Request: Send a blank email to php-general+get-199096@lists.php.net to get a copy of this message
This is a post I sent to the author of this thread. On a unrelated note, any Outlook Express users who can tell me how I can set it up so that when I press "reply", I'd get the commented out previous post(like "REPLY") but I would reply to the php-general LIST and not directly to the AUTHOR? --repost I can tell you from a quick glance that you have the following case function X() { if () { $children=... } elseif () { $children=... } return $children; } Have you tried giving $children an initial value, such as function X() { $children = array(); if () { $children[]=... } elseif () { $children[]=... } if (count($children)>0) return $children; return 0; } I may be getting a head of myself, but the $children[]=... line adds the $descendants into the ARRAY variable, $children. Unless I'm wrong, you MUST declare $children as an ARRAY FIRST(see first line of the function, "$children=array();") Secondly, if you want the function to return 0 if no $descendant entries are added to $children, you must check to see if the $children ARRAY is EMPTY. if (count($children)>0) return $children; that line basically says if ARRAY variable $children has more than 0 elements, return that ARRAY. Finally, return 0; if the ARRAY variable $children has 0 elements(count($children) returns the number of elements in ARRAY variable, $children), "return $children" is NOT executed. The next line is "return 0". This is a lazy way of writing the following : if (count($children)>0) return $children; else return 0; If it seems like I'm explaining too much, it's because from the code snipplet you provided, it sounds like you're a novice to PHP... and you did write, '...explain this error to me'. :-P Hope This Helps -Minuk ----- Original Message ----- From: <php-list@xenonsolutions.com> To: <php-general@lists.php.net> Sent: Saturday, October 09, 2004 10:29 PM Subject: [PHP] > Hello everyone, > > I'm hoping you guys can help me with this error. Here's what I'm getting: > > Notice: Undefined variable: children in > L:\localhost\catalog\catalog_0.1.0\includes\classes\tree.class.php on line > 58 > > This error occurs only when the class's method outputs $children as having > a > value of zero. Below is the class. I want it to return zero but I don't > want > this error. Do I need to change my error settings in my php.ini file? The > error level is currently set to E_ALL and I'm using PHP 5.0.1. If at all > possible, I want to keep this error setting at high because I want > everything to be coded strictly. What did I do wrong in my class and how > can > I fix it to where it doesn't output an error when a class's method returns > a > value of zero? Here's the class: > > function get_children($parent) { > $parent_coord = tree::get_item_coord($parent); > $descendants = $this->get_descendants($parent); > for ($i = 0; $i < count($descendants); $i++) { > if ((empty($children)) && (($parent_coord['0']['lft'] + > 1) == > $descendants[$i]['lft'])) { > $children[] = $descendants[$i]; // found first child > } > elseif (($children[count($children)-1]['rgt'] + 1 == > $descendants[$i]['lft']) && $children[count($children)-1]['rgt'] + > 1 != > $parent_coord['0']['rgt']) { > $children[] = $descendants[$i]; // find next children > } > } > return $children; > } > > > Thanks in advance to anyone that can explain this error to me. > > Nilaab > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#199096) next »