summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-02-04 04:43:40 +0000
committerxue <>2006-02-04 04:43:40 +0000
commitf97358b8da7a2cbb1bf6438298286f7290616381 (patch)
tree6c30830b0d8df8cc6d7e28d6ab9c7d107d3af0ba
parente7a6d7d00239b1d320aafeaa2b90308b83103d85 (diff)
Fixed a bug in TList and TMap about the usage of isset.
-rw-r--r--framework/Collections/TList.php27
-rw-r--r--framework/Collections/TMap.php14
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php4
3 files changed, 24 insertions, 21 deletions
diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php
index f2628231..132f2be6 100644
--- a/framework/Collections/TList.php
+++ b/framework/Collections/TList.php
@@ -90,7 +90,7 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function itemAt($index)
{
- if(isset($this->_d[$index]))
+ if($index>=0 && $index<$this->_c)
return $this->_d[$index];
else
throw new TInvalidDataValueException('list_index_invalid',$index);
@@ -149,15 +149,17 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function removeAt($index)
{
- if(isset($this->_d[$index]))
+ if($index>=0 && $index<$this->_c)
{
- $item=$this->_d[$index];
- if($index===$this->_c-1)
- unset($this->_d[$index]);
+ $this->_c--;
+ if($index===$this->_c)
+ return array_pop($this->_d);
else
+ {
+ $item=$this->_d[$index];
array_splice($this->_d,$index,1);
- $this->_c--;
- return $item;
+ return $item;
+ }
}
else
throw new TInvalidDataValueException('list_index_invalid',$index);
@@ -245,7 +247,7 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function offsetExists($offset)
{
- return isset($this->_d[$offset]);
+ return ($offset>=0 && $offset<$this->_c);
}
/**
@@ -257,7 +259,7 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function offsetGet($offset)
{
- if(isset($this->_d[$offset]))
+ if($offset>=0 && $offset<$this->_c)
return $this->_d[$offset];
else
throw new TInvalidDataValueException('list_index_invalid',$offset);
@@ -317,6 +319,10 @@ class TListIterator implements Iterator
* @var integer index of the current item
*/
private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
/**
* Constructor.
@@ -326,6 +332,7 @@ class TListIterator implements Iterator
{
$this->_d=&$data;
$this->_i=0;
+ $this->_c=count($this->_d);
}
/**
@@ -373,7 +380,7 @@ class TListIterator implements Iterator
*/
public function valid()
{
- return isset($this->_d[$this->_i]);
+ return $this->_i<$this->_c;
}
}
diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php
index be37a46b..4d810503 100644
--- a/framework/Collections/TMap.php
+++ b/framework/Collections/TMap.php
@@ -97,14 +97,12 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess
/**
* Adds an item into the map.
- * Note, if the specified key already exists, the old value will be removed first.
+ * Note, if the specified key already exists, the old value will be overwritten.
* @param mixed key
* @param mixed value
*/
public function add($key,$value)
{
- if(isset($this->_d[$key]))
- $this->remove($key);
$this->_d[$key]=$value;
}
@@ -116,7 +114,7 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function remove($key)
{
- if(isset($this->_d[$key]))
+ if(isset($this->_d[$key]) || array_key_exists($key,$this->_d))
{
$value=$this->_d[$key];
unset($this->_d[$key]);
@@ -141,7 +139,7 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess
*/
public function contains($key)
{
- return isset($this->_d[$key]);
+ return isset($this->_d[$key]) || array_key_exists($key,$this->_d);
}
/**
@@ -305,11 +303,7 @@ class TMapIterator implements Iterator
*/
public function next()
{
- do
- {
- $this->_key=next($this->_keys);
- }
- while(!isset($this->_d[$this->_key]) && $this->_key!==false);
+ $this->_key=next($this->_keys);
}
/**
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index f8dd0b17..f7f51e04 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -773,7 +773,7 @@ class TDataGrid extends TBaseDataList
else
$this->_autoColumns=null;
$state=$this->getViewState('Columns',array());
- if($this->_columns)
+ if($this->_columns && $this->_columns->getCount()===count($state))
{
$i=0;
foreach($this->_columns as $column)
@@ -824,6 +824,8 @@ class TDataGrid extends TBaseDataList
$columns=new TList($this->getColumns());
$columns->mergeWith($this->_autoColumns);
+ $items=$this->getItems();
+
if($columns->getCount()>0)
{
foreach($columns as $column)