SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Removing Object in a Linked List
Threaded View
-
Apr 5, 2009, 17:58 #1
- Join Date
- Jul 2006
- Location
- Augusta, Georgia, United States
- Posts
- 4,194
- Mentioned
- 17 Post(s)
- Tagged
- 5 Thread(s)
Removing Object in a Linked List
What would be the best way to actually remove the object from the linked list here rather then hide it?
PHP Code:<?php
class Attribute {
protected $name;
protected $value;
protected $attribute;
protected $active = true;
public function __construct($name='',$value='') {
$this->setName($name);
$this->setValue($value);
}
public function setName($name) {
$this->name = $name;
}
public function setValue($value) {
$this->value = $value;
}
public function getName() {
return $this->name;
}
public function getValue() {
return $this->value;
}
public function addAttribute($name,$value) {
if($this->attribute) {
$this->attribute->addAttribute($name,$value);
} else {
$this->attribute = new Attribute($name,$value);
}
return $this;
}
public function removeAttribute($name) {
if(strcasecmp($this->getName(),$name)==0) {
$this->active = false;
}
if($this->attribute) {
$this->attribute->removeAttribute($name);
}
return $this;
}
public function render() {
$str = $this->active?$this->getName().'="'.$this->getValue().'"':'';
if($this->attribute) {
$str.= ' '.$this->attribute->render();
}
return $str;
}
}PHP Code:$attribute = new Attribute('id','order-form');
echo
$attribute
->addAttribute('class','form')
->addAttribute('method','post')
->addAttribute('action','/index.php')
->removeAttribute('class')
->removeAttribute('action')
->render();
Bookmarks