Development

Changeset 10835

You must first sign up to be able to contribute.

Changeset 10835

Show
Ignore:
Timestamp:
08/13/08 13:58:38 (11 months ago)
Author:
fabien
Message:

[1.2] fixed sfRequest:hasParameter() doesn't allow for NULL values (closes #2118)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r10834 r10835  
    172172 
    173173The `redirect()` method already have this feature. 
     174 
     175sfParameterHolder 
     176----------------- 
     177 
     178The `has()` method of `sfParameterHolder` has been changed to be more 
     179semantically correct. 
     180 
     181It now returns `true` even if the value is `null`: 
     182 
     183    [php] 
     184    $ph = new sfParameterHolder(); 
     185    $ph->set('foo', 'bar'); 
     186    $ph->set('bar', null); 
     187 
     188    $ph->has('foo') === true; 
     189    $ph->has('bar') === true; // returns false under symfony 1.0 or 1.1 
     190 
     191The `sfParameterHolder::has()` method is used by the `hasParameter()` and 
     192`hasAttribute()` methods available for a large number of core classes. 
  • branches/1.2/lib/util/sfParameterHolder.class.php

    r9051 r10835  
    5151  public function & get($name, $default = null) 
    5252  { 
    53     if (isset($this->parameters[$name])) 
     53    if (array_key_exists($name, $this->parameters)) 
    5454    { 
    5555      $value = & $this->parameters[$name]; 
     
    9292  public function has($name) 
    9393  { 
    94     if (isset($this->parameters[$name])) 
     94    if (array_key_exists($name, $this->parameters)) 
    9595    { 
    9696      return true; 
  • branches/1.2/test/unit/util/sfParameterHolderTest.php

    r9143 r10835  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(27, new lime_output_color()); 
     13$t = new lime_test(28, new lime_output_color()); 
    1414 
    1515// ->clear() 
     
    3030$t->is($ph->get('bar'), null, '->get() returns null if the key does not exist'); 
    3131 
    32 // checks that get returnes reference 
     32// checks that get returns reference 
    3333$ref = 'foobar'; 
    34 $ph->set('ref',$ref); 
    35 $ref2 &= $ph->get('ref'); //obtain the very same reference and modify it 
     34$ph->set('ref', $ref); 
     35$ref2 = null; 
     36$ref2 &= $ph->get('ref'); // obtain the very same reference and modify it 
    3637$ref2 &= 'barfoo'; 
    3738$t->is($ref2 , $ref, '->get() returns a reference for the given key'); 
    38  
    3939 
    4040$ph = new sfParameterHolder(); 
     
    6262$t->is($ph->has('foo'), true, '->has() returns true if the key exists'); 
    6363$t->is($ph->has('bar'), false, '->has() returns false if the key does not exist'); 
     64$ph->set('bar', null); 
     65$t->is($ph->has('bar'), true, '->has() returns true if the key exist, even if the value is null'); 
    6466 
    6567// ->remove() 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.