#40792 [NEW]: Wish: Function array_get(&$mixed, $key, $defaultvalue)

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40792 [NEW]: Wish: Function array_get(&$mixed, $key, $defaultvalue)

    From: t dot kloppenburg at billiton dot de
    Operating system: Linux
    PHP version: 5.2.1
    PHP Bug Type: Feature/Change Request
    Bug description: Wish: Function array_get(&$mixed, $key, $defaultvalue)

    Description:
    ------------
    I miss a function or ArrayObject method to get an element of an array, or
    alternativly a default value if the key is not set in the array.

    In python:
    mydict = {'key1' : 'value1'}
    val = mydict.get('otherkey', 'defaultvalue')
    -> 'defaultvalue'

    This is very handy when dealing with arrays.

    I'ld be happy to see this in PHP4 and PHP5. It could look like this:

    $cfg = array('version' => '1.2v', 'othercfg' => 'otherval');
    $tmppath = array_get( $cfg, 'tmppath', '/tmp' );
    -> '/tmp'

    or with ArrayObject as:
    $tmppath = $arrobj->get( 'tmppath', '/tmp' );
    -> '/tmp' (if not set in the array)

    I code in Python since 6 or 7 years, and I really miss this function in
    everyday-use.



    --
    Edit bug report at [url]http://bugs.php.net/?id=40792&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40792&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40792&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40792&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40792&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40792&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40792&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40792&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40792&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40792&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40792&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40792&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40792&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40792&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40792&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40792&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40792&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40792&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40792&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40792&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40792&r=mysqlcfg[/url]
    t dot kloppenburg at billiton dot de Guest

  2. Similar Questions and Discussions

    1. DefaultValue attribute doesn't get set in a composite custom control
      I have a simple composite control with the following attributes: public string NameLabelText { get { EnsureChildControls(); return...
    2. DefaultValue for Public Property of ASP.NET 2.0 UserControl not appearing in Properties Window
      First, I'm using Visual Web Developer 2005 Express Edition, which I hope is exactly the same as Visual Studio 2005 minus a bunch of useful...
    3. DefaultValue not working (string)
      My defaultvalue attribute is not working. If i drop this control from thetoolbox onto my page the properties are empty. They keep being empty if i...
    4. mixed up sprites
      I'm having a rather strange / frustrating navigation issue. Here's the scenario: On one frame I have a full-screen flash sprite. A few frames down...
    5. ADMINISTRATOR MIXED UP
      I think you renamed your Administrator account to "Rick". Enter %userprofile% to see what profile your "Rick" account is using. If it is...
  3. #2

    Default #40792 [Opn]: Wish: Function array_get(&$mixed, $key, $defaultvalue)

    ID: 40792
    User updated by: t dot kloppenburg at billiton dot de
    Reported By: t dot kloppenburg at billiton dot de
    Status: Open
    Bug Type: Feature/Change Request
    Operating System: Linux
    PHP Version: 5.2.1
    New Comment:

    ok, I code in PHP all this years and I miss it in PHP :)


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-13 11:23:03] t dot kloppenburg at billiton dot de

    Description:
    ------------
    I miss a function or ArrayObject method to get an element of an array,
    or alternativly a default value if the key is not set in the array.

    In python:
    mydict = {'key1' : 'value1'}
    val = mydict.get('otherkey', 'defaultvalue')
    -> 'defaultvalue'

    This is very handy when dealing with arrays.

    I'ld be happy to see this in PHP4 and PHP5. It could look like this:

    $cfg = array('version' => '1.2v', 'othercfg' => 'otherval');
    $tmppath = array_get( $cfg, 'tmppath', '/tmp' );
    -> '/tmp'

    or with ArrayObject as:
    $tmppath = $arrobj->get( 'tmppath', '/tmp' );
    -> '/tmp' (if not set in the array)

    I code in Python since 6 or 7 years, and I really miss this function in
    everyday-use.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40792&edit=1[/url]
    t dot kloppenburg at billiton dot de Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139