Re: [PHP] class problem :(
On Thu, May 28, 2009 at 4:28 PM, Luke wrote: > Any ideas? Perhaps there is a different way I could implement the classes - > I would rather not have getObjectIds repeated three times! just make the classes instance-based, thats your easiest bet. (sorry for the extra noise) abstract class ForumObject { private $table; function getObjectIds ($field, $value) { $query = "SELECT id FROM {$this->table} WHERE $field = '$value'"; $object_ids = mysql_fetch_array(); return $object_ids; } } painful, i know.. which is why static inheritance is one of the headliners in 5.3. -nathan
Re: [PHP] class problem :(
On Thu, May 28, 2009 at 4:28 PM, Luke wrote: > Right I've read the manual on this and all that so hopefully you find > people > can help. > I have an abstract class with three children. The abstract is ForumObject > and the three children are Thread, Category and Post and each have their > own > table so I wrote the following: > abstract class ForumObject > { > static private $table; > > static function getObjectIds ($field, $value) > { > $query = "SELECT id FROM {self::$table} WHERE $field = '$value'"; > $object_ids = mysql_fetch_array(); > return $object_ids; > } > } > > class Category extends ForumObject > { > static private $table = "categories"; > } > That's just got the important bits for the sake of your eyes but basically > the problem I'm having is calling > Category::getObjectIds ($whatever, $whatever2); > Seems to think that it's referring to ForumObject::$table rather than > Category::$table? > I looked into it and there seems to be something you can do with > get_called_class() but unfortunately I'm stuck with 5.2.9 at the moment and > that is new to 5.3. > Any ideas? Perhaps there is a different way I could implement the classes - > I would rather not have getObjectIds repeated three times! > Thanks in advance, this is a limitation in pre-5.3 php wherein there is no support for static inheritance. another way to do it in 5.3, inside of the ForumObject::getObjectId() method is to use static::$table which will correctly resolve the lookup to the class youd expect. -nathan
[PHP] class problem
Right I've read the manual on this and all that so hopefully you fine people can help. I have an abstract class with three children. The abstract is ForumObject and the three children are Thread, Category and Post and each have their own table so I wrote the following: abstract class ForumObject { static private $table; static function getObjectIds ($field, $value) { $query = "SELECT id FROM {self::$table} WHERE $field = '$value'"; $object_ids = mysql_fetch_array(); return $object_ids; } } class Category extends ForumObject { static private $table = "categories"; } That's just got the important bits for the sake of your eyes but basically the problem I'm having is calling Category::getObjectIds ($whatever, $whatever2); Seems to think that it's referring to ForumObject::$table rather than Category::$table? I looked into it and there seems to be something you can do with get_called_class() but unfortunately I'm stuck with 5.2.9 at the moment and that is new to 5.3. Any ideas? Perhaps there is a different way I could implement the classes - I would rather not have getObjectIds repeated three times! Thanks in advance, -- Luke Slater http://dinosaur-os.com/ :O)
[PHP] class problem :(
Right I've read the manual on this and all that so hopefully you find people can help. I have an abstract class with three children. The abstract is ForumObject and the three children are Thread, Category and Post and each have their own table so I wrote the following: abstract class ForumObject { static private $table; static function getObjectIds ($field, $value) { $query = "SELECT id FROM {self::$table} WHERE $field = '$value'"; $object_ids = mysql_fetch_array(); return $object_ids; } } class Category extends ForumObject { static private $table = "categories"; } That's just got the important bits for the sake of your eyes but basically the problem I'm having is calling Category::getObjectIds ($whatever, $whatever2); Seems to think that it's referring to ForumObject::$table rather than Category::$table? I looked into it and there seems to be something you can do with get_called_class() but unfortunately I'm stuck with 5.2.9 at the moment and that is new to 5.3. Any ideas? Perhaps there is a different way I could implement the classes - I would rather not have getObjectIds repeated three times! Thanks in advance, -- Luke Slater :O)
[PHP] class problem
Hello, I have a problem. Here is code: p1 = $p1; $this->p2 = $p2; } function getP1() { return $this->p1; } function setP1($p1) { $this->p1 = $p1; } function getP2() { return $this->p2; } function setP2($p2) { $this->p2 = $p2; } function toString() { return "p1=" . $this->p1 . "; p2=" . $this->p2; } } class Obj2 { var $p1; var $p2; var $obj1; function Obj2 () { } function init($p1, $p2, $obj1) { $this->p1 = $p1; $this->p2 = $p2; $this->obj1 = $obj1; } function getP1() { return $this->p1; } function setP1($p1) { $this->p1 = $p1; } function getP2() { return $this->p2; } function setP2($p2) { $this->p2 = $p2; } function getObj1() { return $this->obj1; } function setObj1($obj1) { $this->obj1 = $obj1; } function toString() { return "p1=" . $this->p1 . "; p2=" . $this->p2 . "; obj1=" . $this->obj1->toString(); } } $objs[] = new Obj1("jurek", "mizgiert"); $objs[] = new Obj1("marta", "wegner"); $objs[] = new Obj1("tomasz", "zdybicki"); $objs[] = new Obj1("artur", "milczarek"); $obj2 = new Obj2(); $tmp = Array(); for ($i = 0; $i < count($objs); $i++) { $obj2->init($i, $i, $objs[$i]); $tmp[] = $obj2; print ($i+1) . ". " . $obj2->toString() . " | "; $o = $tmp[$i]; $o2 = $o->getObj1(); print ($i+1) . ". p1=" . $o->getP1() . "; p2=" . $o->getP2() . "; obj1=p1=" . $o2->getP1() . "; p2=" . $o2->getP2() . ""; } print ""; print count($tmp); print ""; for ($i = 0; $i < count($tmp); $i++) { $o = $tmp[$i]; $o2 = $o->getObj1(); print ($i+1) . ". p1=" . $o->getP1() . "; p2=" . $o->getP2() . "; obj1=p1=" . $o2->getP1() . "; p2=" . $o2->getP2() . ""; } ?> Class Obj1 have 2 fields with set-get methods and constructor which inits fields. Method toString() return string representation of fields... Second class Obj2 have 3 fields from which the obj1 will be type Obj1. Method init inits fields of class. Method toString make the same action like in Obj1 Look at code near the classes. Run this give this effect: 1. p1=0; p2=0; obj1=p1=jurek; p2=mizgiert | 1. p1=0; p2=0; obj1=p1=jurek; p2=mizgiert 2. p1=1; p2=1; obj1=p1=marta; p2=wegner | 2. p1=1; p2=1; obj1=p1=marta; p2=wegner 3. p1=2; p2=2; obj1=p1=tomasz; p2=zdybicki | 3. p1=2; p2=2; obj1=p1=tomasz; p2=zdybicki 4. p1=3; p2=3; obj1=p1=artur; p2=milczarek | 4. p1=3; p2=3; obj1=p1=artur; p2=milczarek 4 1. p1=0; p2=0; obj1=p1=jurek; p2=mizgiert 2. p1=1; p2=1; obj1=p1=artur; p2=milczarek 3. p1=2; p2=2; obj1=p1=artur; p2=milczarek 4. p1=3; p2=3; obj1=p1=artur; p2=milczarek This is wrong result because effect before the myst be the same after . When I change method toString() in class Obj2 to return ""; it will be ok (look below). What is going on? Who knows? 1. | 1. p1=0; p2=0; obj1=p1=jurek; p2=mizgiert 2. | 2. p1=1; p2=1; obj1=p1=marta; p2=wegner 3. | 3. p1=2; p2=2; obj1=p1=tomasz; p2=zdybicki 4. | 4. p1=3; p2=3; obj1=p1=artur; p2=milczarek 4 1. p1=0; p2=0; obj1=p1=jurek; p2=mizgiert 2. p1=1; p2=1; obj1=p1=marta; p2=wegner 3. p1=2; p2=2; obj1=p1=tomasz; p2=zdybicki 4. p1=3; p2=3; obj1=p1=artur; p2=milczarek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class Problem
Hi there. Try doing it this way: You need to access the class's variable using the $this identifier e.g. > class MenueItem { > var $ID_Menue; > var $Name; > var $Parent_ID; > var $Next_ID; > var $Prev_ID; > > > function Write() { > echo "Parent_ID: " . $this->Parent_ID . "";// Not $MI > //(no output at all!) > } > > Regards -Scott David Eggler wrote: > I create a Instance fo the Class MenueItem in Menue. I change the value of > one of its variables. But when i call the function within MenueItem there > seems not to be a value: > The intresting thing is it works with Other variables, even i cant echo > them, they have a value > > Thanks for help > > class Menue { > > function Makechilde($somvalue) { > echo "Next_ID: " . $Parent_ID . ""; //Works > $MI->Parent_ID = $Parent_ID; > echo "Parent_ID: " . $MI->Parent_ID . "";//correct output > $MI->write(); > > } > } > > class MenueItem { > var $ID_Menue; > var $Name; > var $Parent_ID; > var $Next_ID; > var $Prev_ID; > > > function Write() { > echo "Parent_ID: " . $MI->Parent_ID . ""; > //(no output at all!) > } > > } > > -- //// // Scott Houseman // // Jam Warehouse http://www.jamwarehouse.com/ // // Smart Business Innovation // // +27 21 4477440 / +27 82 4918021// //// -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] class Problem
I create a Instance fo the Class MenueItem in Menue. I change the value of one of its variables. But when i call the function within MenueItem there seems not to be a value: The intresting thing is it works with Other variables, even i cant echo them, they have a value Thanks for help class Menue { function Makechilde($somvalue) { echo "Next_ID: " . $Parent_ID . ""; //Works $MI->Parent_ID = $Parent_ID; echo "Parent_ID: " . $MI->Parent_ID . "";//correct output $MI->write(); } } class MenueItem { var $ID_Menue; var $Name; var $Parent_ID; var $Next_ID; var $Prev_ID; function Write() { echo "Parent_ID: " . $MI->Parent_ID . ""; //(no output at all!) } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class problem - Fatal error:
> Fatal error: Cannot redeclare class dmsql in It looks like you are after include_once http://www.php.net/manual/en/function.include-once.php Todd - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, August 29, 2002 2:48 PM Subject: [PHP] Class problem - Fatal error: > Hello I get this error: > > Fatal error: Cannot redeclare class dmsql in > /usr/local/apache/htdocs/dm/inc/sql.inc.php on line 4 > > It happens when a user presses the back button, otherwise when the page > is first loaded it works fine. > > Here's the file called with web browser > > include('class_dmsql.inc.php'); > include('class_b.inc.php'); > > $r = new class_b > > Please note that class_b extends class dmsql, > > Can anyone help me ? > > Thanks > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Class problem - Fatal error:
Hello I get this error: Fatal error: Cannot redeclare class dmsql in /usr/local/apache/htdocs/dm/inc/sql.inc.php on line 4 It happens when a user presses the back button, otherwise when the page is first loaded it works fine. Here's the file called with web browser include('class_dmsql.inc.php'); include('class_b.inc.php'); $r = new class_b Please note that class_b extends class dmsql, Can anyone help me ? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php