Object properties in echo()

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

  1. #1

    Default Object properties in echo()

    I started using PHP's object-oriented stuff a little while ago, which has
    mostly been a joy. However, I've noticed that they don't seem to echo as I
    would like. Eg:

    $this->field['id'] = 255;
    $this->key = 'id';
    echo "$this->key is $this->field[$this->key]"; // prints "id is Array[id]"

    // Thus I am forced to do this
    $keyval = $this->field[$this->key];
    echo "this->key is $keyval"; // prints "id is 255"
    echo "this->key is " . $this->field[$this->key]; // also works

    This example is trivial, but it becomes much more of a nuisance when I'm
    making forms and whatnot and don't want to have to define a whole bunch of
    new variables or keep opening and closing quotes. Is there a workaround or
    different syntax I can use for this, or am I just stuck?

    Jesse S. Bangs [email]jaspax@u.washington.edu[/email]
    [url]http://students.washington.edu/jaspax/[/url]
    [url]http://students.washington.edu/jaspax/blog[/url]

    Jesus asked them, "Who do you say that I am?"

    And they answered, "You are the eschatological manifestation of the ground
    of our being, the kerygma in which we find the ultimate meaning of our
    interpersonal relationship."

    And Jesus said, "What?"
    JS Bangs Guest

  2. Similar Questions and Discussions

    1. object properties
      I am using the trial version of Contribute CS3. When I edit a page and select a check-box or field, how can I inspect and change its properties? The...
    2. listing Object properties from SearchResult
      Hi I have the following lines of code that are suppose to list some selected properties of all the object entries in a SearchResult but the code is...
    3. The Sound Object - causing an echo effect---help!
      Hi everybody My problem is that i'm trying to get an audio sample playing at the start of the movie. In my first frame scene i create the sound...
    4. losing object properties when...
      i lose the capability to change an object's width and height in the properties tab after using the extrude tool on it. the properties tab then just...
    5. Accessing all properties of an object at Runtime
      Use reflection... "Softwaremaker" <msdn@removethis.softwaremaker.net> wrote in message news:<#b1mBjhQDHA.2432@TK2MSFTNGP10.phx.gbl>...
  3. #2

    Default Re: Object properties in echo()

    JS Bangs:
    > I started using PHP's object-oriented stuff a little while ago, which has
    > mostly been a joy. However, I've noticed that they don't seem to echo as I
    > would like. Eg:
    >
    > $this->field['id'] = 255;
    > $this->key = 'id';
    > echo "$this->key is $this->field[$this->key]"; // prints "id is Array[id]"
    >
    > // Thus I am forced to do this
    > $keyval = $this->field[$this->key];
    > echo "this->key is $keyval"; // prints "id is 255"
    > echo "this->key is " . $this->field[$this->key]; // also works
    >
    > This example is trivial, but it becomes much more of a nuisance when I'm
    > making forms and whatnot and don't want to have to define a whole bunch of
    > new variables or keep opening and closing quotes. Is there a workaround or
    > different syntax I can use for this, or am I just stuck?
    Yeah, enclose them in {}, e.g.:
    "{$this->key} is {$this->field[$this->key]}";

    See:
    [url]http://www.php.net/manual/en/language.types.string.php#language.types.string.pa rsing[/url]
    and in particular:
    [url]http://www.php.net/manual/en/language.types.string.php#language.types.string.pa rsing.complex[/url]

    André Nęss
    André Nęss 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