Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8669 > unrolled thread

question about class getters

Started byDavid Heller <daveh@allheller.net>
First post2013-03-15 08:42 -0700
Last post2013-03-23 08:46 -0400
Articles 12 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  question about class getters David Heller <daveh@allheller.net> - 2013-03-15 08:42 -0700
    Re: question about class getters Salvatore <sal@yojimbo.hack.invalid> - 2013-03-15 16:12 +0000
      Re: question about class getters David Heller <daveh@allheller.net> - 2013-03-15 09:48 -0700
        Re: question about class getters "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-16 12:06 +0100
    Re: question about class getters Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-15 13:11 -0400
      Re: question about class getters David Heller <daveh@allheller.net> - 2013-03-15 10:53 -0700
        Re: question about class getters Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-15 14:56 -0400
          Re: question about class getters Curtis Dyer <dyer85@gmail.com> - 2013-03-21 09:31 +0000
            Re: question about class getters Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-21 08:55 -0400
              Re: question about class getters Christoph Becker <cmbecker69@gmx.de> - 2013-03-21 14:12 +0100
              Re: question about class getters Curtis Dyer <dyer85@gmail.com> - 2013-03-23 07:14 +0000
                Re: question about class getters Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-23 08:46 -0400

#8669 — question about class getters

FromDavid Heller <daveh@allheller.net>
Date2013-03-15 08:42 -0700
Subjectquestion about class getters
Message-ID<acaaecf6-a484-4603-8c21-6dad66988e18@c6g2000yqh.googlegroups.com>
Hello

I have the following code snippet:

Class myClass

{
 public function makeArray()
{
$this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
'Sat', 'Sun');
}
pubic function getArray()
{
 return $this->my_array;
}
}

and then do the following

var $MyVar = new myClass();
var $mydate = $MyVar->getArray[1];
echo $mydate;
=> Mon
will this work? If not how to make it work?

Thanks,

Dave

[toc] | [next] | [standalone]


#8670

FromSalvatore <sal@yojimbo.hack.invalid>
Date2013-03-15 16:12 +0000
Message-ID<khvh8s$13k6$1@yojimbo.hack>
In reply to#8669
On 2013-03-15, David Heller <daveh@allheller.net> wrote:
> var $MyVar = new myClass();
> var $mydate = $MyVar->getArray[1];
> echo $mydate;
>=> Mon
> will this work? If not how to make it work?

Ah, I see now. Well, to answer your first question, it won't work. The
type of $MyVar->getArray is function (or callback), not array.

The proper way of writing a getter in PHP is like so:

<?php
class myClass {
    private $_array = array();

    public function __get($name) {
        switch ($name) {
        case 'array':
            break;
        }
    }
}
?>

In this example, when you fetch "$MyVar->array" you will get the array
by value and not by reference, so the following code will work...

<?php
$MyVar = new myClass();
$mydate = $MyVar->array[1];
?>

...but the following code won't...

<?php
$MyVar = new myClass();
$mydate = 'Mon';
$MyVar->array[1] = $mydate;
?>

...because the property $_array will never be manipulated.

Do you want to be able to manipulate the array in the object, or just
return the array?

-- 
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++

[toc] | [prev] | [next] | [standalone]


#8671

FromDavid Heller <daveh@allheller.net>
Date2013-03-15 09:48 -0700
Message-ID<045f80bf-c1fe-4ef0-8fcd-ab1de2ebdb09@7g2000yqy.googlegroups.com>
In reply to#8670
On Mar 15, 12:12 pm, Salvatore <s...@yojimbo.hack.invalid> wrote:
> On 2013-03-15, David Heller <da...@allheller.net> wrote:
>
> > var $MyVar = new myClass();
> > var $mydate = $MyVar->getArray[1];
> > echo $mydate;
> >=> Mon
> > will this work? If not how to make it work?
>
> Ah, I see now. Well, to answer your first question, it won't work. The
> type of $MyVar->getArray is function (or callback), not array.
>
> The proper way of writing a getter in PHP is like so:
>
> <?php
> class myClass {
>     private $_array = array();
>
>     public function __get($name) {
>         switch ($name) {
>         case 'array':
>             break;
>         }
>     }}
>
> ?>
>
> In this example, when you fetch "$MyVar->array" you will get the array
> by value and not by reference, so the following code will work...
>
> <?php
> $MyVar = new myClass();
> $mydate = $MyVar->array[1];
> ?>
>
> ...but the following code won't...
>
> <?php
> $MyVar = new myClass();
> $mydate = 'Mon';
> $MyVar->array[1] = $mydate;
> ?>
>
> ...because the property $_array will never be manipulated.
>
> Do you want to be able to manipulate the array in the object, or just
> return the array?
>
> --
> Blah blah bleh...
> GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++

Thanks

I don't need to manipulate the array in the object just get its value.
I am trying to update some php 4.0.6 code that makes liberal use of
the Super Global "$GLOBALS" and eval() (perhaps there was no other way
in php 4.0.6) which I have updated to work with php 5.3 but would like
to rewrite the code completely to not make use of such an unsafe
method of passing variables around! Using a getter method seems to be
the best or better alternative.

Dave

[toc] | [prev] | [next] | [standalone]


#8677

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-03-16 12:06 +0100
Message-ID<aqj211F6braU1@mid.uni-berlin.de>
In reply to#8671
Am 15.03.2013 17:48, schrieb David Heller:
---------
> I don't need to manipulate the array in the object just get its value.
> I am trying to update some php 4.0.6 code that makes liberal use of
> the Super Global "$GLOBALS" and eval() (perhaps there was no other way
> in php 4.0.6) which I have updated to work with php 5.3 but would like
> to rewrite the code completely to not make use of such an unsafe
> method of passing variables around! Using a getter method seems to be
> the best or better alternative.
> 
> Dave
> 

This is an example of what one may call straight coding - just plain features used.

<?php

class Dayofweek {
  # constant init values okay
  private $a = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday','Sat', 'Sun');
  function getDow($n) {
    if ($this->isInbounds($n)) {
        return $this->a[$n];
    } else {
        trigger_error('Dayofweek index out of range', E_USER_ERROR);
    }
  }
  function isInbounds($n) {
    return (-1 < $n && $n < count($this->a));
  }
  function getDow1based($n) {
    return $this->getDow($n-1);
  }
  function getDowTolerant($n) {
    if ($this->isInbounds($n)) return $this->a[$n];
    else return "";
  }
}

/Str.

[toc] | [prev] | [next] | [standalone]


#8672

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-15 13:11 -0400
Message-ID<khvkl7$c5m$1@dont-email.me>
In reply to#8669
On 3/15/2013 11:42 AM, David Heller wrote:
>
> Hello
>
> I have the following code snippet:
>
> Class myClass
>
> {
>   public function makeArray()
> {
> $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
> 'Sat', 'Sun');
> }
> pubic function getArray()
> {
>   return $this->my_array;
> }
> }
>
> and then do the following
>
> var $MyVar = new myClass();
> var $mydate = $MyVar->getArray[1];
> echo $mydate;
> => Mon
> will this work? If not how to make it work?
>
> Thanks,
>
> Dave
>

Not quite, for a couple of reasons.  As Salvatore pointed out, 
getArray() is a function, not a variable, so you need to code it as a 
function.  The other problem is you never called makeArray() and don't 
have a constructor, so $my_array doesn't exist (also it should be 
declared as a class variable).

Something like this should works:

class MyClass {
   private $my_array;

   public function __construct() { // Constructor
     $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
       'Sat', 'Sun');
   }
   public function getArray($i) {
     if ($i >= 0 && $i < count($this->my_array))  // Verify index
       return $this->my_array[$i];
     else
       return null;  // Out of range
   }
}

$myVar = new MyClass();
$mydate = $myVar->getArray(1); // Pass index as an argument
echo $mydate;

=> Tues

(PHP array indexes start with zero, not one).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8673

FromDavid Heller <daveh@allheller.net>
Date2013-03-15 10:53 -0700
Message-ID<d4b5e6d8-c4c5-4aca-a857-71404fe8df5c@7g2000yqy.googlegroups.com>
In reply to#8672
On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 3/15/2013 11:42 AM, David Heller wrote:
>
>
>
>
>
>
>
>
>
>
>
> > Hello
>
> > I have the following code snippet:
>
> > Class myClass
>
> > {
> >   public function makeArray()
> > {
> > $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
> > 'Sat', 'Sun');
> > }
> > pubic function getArray()
> > {
> >   return $this->my_array;
> > }
> > }
>
> > and then do the following
>
> > var $MyVar = new myClass();
> > var $mydate = $MyVar->getArray[1];
> > echo $mydate;
> > => Mon
> > will this work? If not how to make it work?
>
> > Thanks,
>
> > Dave
>
> Not quite, for a couple of reasons.  As Salvatore pointed out,
> getArray() is a function, not a variable, so you need to code it as a
> function.  The other problem is you never called makeArray() and don't
> have a constructor, so $my_array doesn't exist (also it should be
> declared as a class variable).
>
> Something like this should works:
>
> class MyClass {
>    private $my_array;
>
>    public function __construct() { // Constructor
>      $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
>        'Sat', 'Sun');
>    }
>    public function getArray($i) {
>      if ($i >= 0 && $i < count($this->my_array))  // Verify index
>        return $this->my_array[$i];
>      else
>        return null;  // Out of range
>    }
>
> }
>
> $myVar = new MyClass();
> $mydate = $myVar->getArray(1); // Pass index as an argument
> echo $mydate;
>
> => Tues
>
> (PHP array indexes start with zero, not one).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Even better:

class MyClass {
    private $my_array;

    public function __construct() { // Constructor
      $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
        'Sat', 'Sun');
    }
    public function __get($i) {
      // if ($i >= 0 && $i < count($this->my_array))  // Verify index
      if(array_key_exists($i, $this->my_array)){         // For keys
that are non-numerical
  return $this->my_array[$i];}
      else
        return null;  // Out of range or non-existant
    }

 }

I get it now (no pun intended).

Dave

[toc] | [prev] | [next] | [standalone]


#8674

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-15 14:56 -0400
Message-ID<khvqpp$h7g$1@dont-email.me>
In reply to#8673
On 3/15/2013 1:53 PM, David Heller wrote:
> On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 3/15/2013 11:42 AM, David Heller wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> Hello
>>
>>> I have the following code snippet:
>>
>>> Class myClass
>>
>>> {
>>>    public function makeArray()
>>> {
>>> $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
>>> 'Sat', 'Sun');
>>> }
>>> pubic function getArray()
>>> {
>>>    return $this->my_array;
>>> }
>>> }
>>
>>> and then do the following
>>
>>> var $MyVar = new myClass();
>>> var $mydate = $MyVar->getArray[1];
>>> echo $mydate;
>>> => Mon
>>> will this work? If not how to make it work?
>>
>>> Thanks,
>>
>>> Dave
>>
>> Not quite, for a couple of reasons.  As Salvatore pointed out,
>> getArray() is a function, not a variable, so you need to code it as a
>> function.  The other problem is you never called makeArray() and don't
>> have a constructor, so $my_array doesn't exist (also it should be
>> declared as a class variable).
>>
>> Something like this should works:
>>
>> class MyClass {
>>     private $my_array;
>>
>>     public function __construct() { // Constructor
>>       $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
>>         'Sat', 'Sun');
>>     }
>>     public function getArray($i) {
>>       if ($i >= 0 && $i < count($this->my_array))  // Verify index
>>         return $this->my_array[$i];
>>       else
>>         return null;  // Out of range
>>     }
>>
>> }
>>
>> $myVar = new MyClass();
>> $mydate = $myVar->getArray(1); // Pass index as an argument
>> echo $mydate;
>>
>> => Tues
>>
>> (PHP array indexes start with zero, not one).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Even better:
>
> class MyClass {
>      private $my_array;
>
>      public function __construct() { // Constructor
>        $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs', 'Friday',
>          'Sat', 'Sun');
>      }
>      public function __get($i) {
>        // if ($i >= 0 && $i < count($this->my_array))  // Verify index
>        if(array_key_exists($i, $this->my_array)){         // For keys
> that are non-numerical
>    return $this->my_array[$i];}
>        else
>          return null;  // Out of range or non-existant
>      }
>
>   }
>
> I get it now (no pun intended).
>
> Dave
>

No, __get is a "magic method" and used to access properties for which 
you have no special getter method.  You need to pass the name of the 
property you wish.  It really doesn't conform to OO standards, and as 
your object complexity increases, the complexity of your magic methods 
increases.  It's also not applicable to passing additional parameters, 
such as the index you wish.

I really prefer to use individual getter and setter methods for object 
properties, as is indicated in OO principles.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8775

FromCurtis Dyer <dyer85@gmail.com>
Date2013-03-21 09:31 +0000
Message-ID<kiek0l$vq1$1@dont-email.me>
In reply to#8674
Jerry Stuckle <jstucklex@attglobal.net> wrote:

> On 3/15/2013 1:53 PM, David Heller wrote:
>> On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net>
>> wrote: 
>>> On 3/15/2013 11:42 AM, David Heller wrote:
>>>
>>>> Hello
>>>
>>>> I have the following code snippet:
>>>
>>>> Class myClass
>>>
>>>> {
>>>>    public function makeArray()
>>>> {
>>>> $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs',
>>>> 'Friday', 'Sat', 'Sun');
>>>> }
>>>> pubic function getArray()
>>>> {
>>>>    return $this->my_array;
>>>> }
>>>> }
>>>
>>>> and then do the following
>>>
>>>> var $MyVar = new myClass();
>>>> var $mydate = $MyVar->getArray[1];
>>>> echo $mydate;
>>>> => Mon
>>>> will this work? If not how to make it work?

Why not try first and see what happens?

<snip>

>>> Not quite, for a couple of reasons.  As Salvatore pointed out,
>>> getArray() is a function, not a variable, so you need to code
>>> it as a function.  The other problem is you never called
>>> makeArray() and don't have a constructor, so $my_array doesn't
>>> exist (also it should be declared as a class variable).
>>>
>>> Something like this should works:

<snip code>

>> Even better:
>>
>> class MyClass {
>>      private $my_array;
>>
>>      public function __construct() { // Constructor
>>        $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs',
>>        'Friday', 
>>          'Sat', 'Sun');

Just out of curiosity, why is `Friday' the only day of the week 
that's not abbreviated in your list?

>>      }
>>      public function __get($i) {
>>        // if ($i >= 0 && $i < count($this->my_array))  //
>>        Verify index if(array_key_exists($i, $this->my_array)){ 
>>               // For keys 
>> that are non-numerical
>>    return $this->my_array[$i];}
>>        else
>>          return null;  // Out of range or non-existant
>>      }
>>
>>   }
>>
>> I get it now (no pun intended).
> 
> No, __get is a "magic method" and used to access properties for
> which you have no special getter method.  You need to pass the
> name of the property you wish.

Magic methods like `__get()' are called when "inaccessible" 
properties or methods are invoked, at which point you may handle 
the call any way you wish. According to the PHP manual[1], 
"inaccessible" methods and properties include those which are not 
defined, so you don't need to specify the names of actual class 
members for `__get()' to work.


[1]: <http://php.net/__get>

<snip>

> It's also not
> applicable to passing additional parameters, such as the index
> you wish. 

Yes, the `__get()' magic method expects a string, and moreover, if 
the OP intends to use the class similarly to the code they posted 
initially, it would be a syntax error:

  echo $obj->2; /* parse error */

Using a custom getter method as you posted above, IMO, seems 
easiest.

-- 
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>

[toc] | [prev] | [next] | [standalone]


#8778

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-21 08:55 -0400
Message-ID<kievso$9hu$1@dont-email.me>
In reply to#8775
On 3/21/2013 5:31 AM, Curtis Dyer wrote:
> Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
>> On 3/15/2013 1:53 PM, David Heller wrote:
>>> On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net>
>>> wrote:
>>>> On 3/15/2013 11:42 AM, David Heller wrote:
>>>>
>>>>> Hello
>>>>
>>>>> I have the following code snippet:
>>>>
>>>>> Class myClass
>>>>
>>>>> {
>>>>>     public function makeArray()
>>>>> {
>>>>> $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs',
>>>>> 'Friday', 'Sat', 'Sun');
>>>>> }
>>>>> pubic function getArray()
>>>>> {
>>>>>     return $this->my_array;
>>>>> }
>>>>> }
>>>>
>>>>> and then do the following
>>>>
>>>>> var $MyVar = new myClass();
>>>>> var $mydate = $MyVar->getArray[1];
>>>>> echo $mydate;
>>>>> => Mon
>>>>> will this work? If not how to make it work?
>
> Why not try first and see what happens?
>
> <snip>
>
>>>> Not quite, for a couple of reasons.  As Salvatore pointed out,
>>>> getArray() is a function, not a variable, so you need to code
>>>> it as a function.  The other problem is you never called
>>>> makeArray() and don't have a constructor, so $my_array doesn't
>>>> exist (also it should be declared as a class variable).
>>>>
>>>> Something like this should works:
>
> <snip code>
>
>>> Even better:
>>>
>>> class MyClass {
>>>       private $my_array;
>>>
>>>       public function __construct() { // Constructor
>>>         $this->my_array = array('Mon', 'Tues', 'Wed', 'Thurs',
>>>         'Friday',
>>>           'Sat', 'Sun');
>
> Just out of curiosity, why is `Friday' the only day of the week
> that's not abbreviated in your list?
>

It's not my list.

>>>       }
>>>       public function __get($i) {
>>>         // if ($i >= 0 && $i < count($this->my_array))  //
>>>         Verify index if(array_key_exists($i, $this->my_array)){
>>>                // For keys
>>> that are non-numerical
>>>     return $this->my_array[$i];}
>>>         else
>>>           return null;  // Out of range or non-existant
>>>       }
>>>
>>>    }
>>>
>>> I get it now (no pun intended).
>>
>> No, __get is a "magic method" and used to access properties for
>> which you have no special getter method.  You need to pass the
>> name of the property you wish.
>
> Magic methods like `__get()' are called when "inaccessible"
> properties or methods are invoked, at which point you may handle
> the call any way you wish. According to the PHP manual[1],
> "inaccessible" methods and properties include those which are not
> defined, so you don't need to specify the names of actual class
> members for `__get()' to work.
>

Yes, I know what magic methods are.  But that doesn't mean you can't 
call the method directly.

>
> [1]: <http://php.net/__get>
>
> <snip>
>
>> It's also not
>> applicable to passing additional parameters, such as the index
>> you wish.
>
> Yes, the `__get()' magic method expects a string, and moreover, if
> the OP intends to use the class similarly to the code they posted
> initially, it would be a syntax error:
>
>    echo $obj->2; /* parse error */
>
> Using a custom getter method as you posted above, IMO, seems
> easiest.
>

echo $obj->'2'; should work (although I haven't tried it).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8780

FromChristoph Becker <cmbecker69@gmx.de>
Date2013-03-21 14:12 +0100
Message-ID<kif0v6$m43$1@speranza.aioe.org>
In reply to#8778
Jerry Stuckle wrote:

> echo $obj->'2'; should work (although I haven't tried it).

That is a syntactic error.  FWIW the following works:

  PHP 5.4.7 (cli) (???) [WINNT]
  >>> class Test {function __get($i) {return $i;}}
  >>> $obj = new Test
  >>> $obj->{2}
  >>> echo $obj->{2}
  2

However, I wouldn't use it.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#8806

FromCurtis Dyer <dyer85@gmail.com>
Date2013-03-23 07:14 +0000
Message-ID<kijkpc$g83$1@dont-email.me>
In reply to#8778
Jerry Stuckle <jstucklex@attglobal.net> wrote:

> On 3/21/2013 5:31 AM, Curtis Dyer wrote:
>> Jerry Stuckle <jstucklex@attglobal.net> wrote:
>>
>>> On 3/15/2013 1:53 PM, David Heller wrote:
>>>> On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net>
>>>> wrote:
>>>>> On 3/15/2013 11:42 AM, David Heller wrote:

<snip>

>>>>       public function __construct() { // Constructor
>>>>         $this->my_array = array('Mon', 'Tues', 'Wed',
>>>>         'Thurs', 'Friday',
>>>>           'Sat', 'Sun');
>>
>> Just out of curiosity, why is `Friday' the only day of the week
>> that's not abbreviated in your list?
> 
> It's not my list.

Right, but this portion of my response was to the OP. If I botched 
my quoting, my apologies.

<snip>

>> Yes, the `__get()' magic method expects a string, and moreover,
>> if the OP intends to use the class similarly to the code they
>> posted initially, it would be a syntax error:
>>
>>    echo $obj->2; /* parse error */
>>
>> Using a custom getter method as you posted above, IMO, seems
>> easiest.
> 
> echo $obj->'2'; should work (although I haven't tried it).

That's still a syntax error; I tested in 5.4.12. However, I haven't 
bothered to check if it works in prior versions.

-- 
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>

[toc] | [prev] | [next] | [standalone]


#8807

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-23 08:46 -0400
Message-ID<kik834$cud$1@dont-email.me>
In reply to#8806
On 3/23/2013 3:14 AM, Curtis Dyer wrote:
> Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
>> On 3/21/2013 5:31 AM, Curtis Dyer wrote:
>>> Jerry Stuckle <jstucklex@attglobal.net> wrote:
>>>
>>>> On 3/15/2013 1:53 PM, David Heller wrote:
>>>>> On Mar 15, 1:11 pm, Jerry Stuckle <jstuck...@attglobal.net>
>>>>> wrote:
>>>>>> On 3/15/2013 11:42 AM, David Heller wrote:
>
> <snip>
>
>>>>>        public function __construct() { // Constructor
>>>>>          $this->my_array = array('Mon', 'Tues', 'Wed',
>>>>>          'Thurs', 'Friday',
>>>>>            'Sat', 'Sun');
>>>
>>> Just out of curiosity, why is `Friday' the only day of the week
>>> that's not abbreviated in your list?
>>
>> It's not my list.
>
> Right, but this portion of my response was to the OP. If I botched
> my quoting, my apologies.
>
> <snip>
>
>>> Yes, the `__get()' magic method expects a string, and moreover,
>>> if the OP intends to use the class similarly to the code they
>>> posted initially, it would be a syntax error:
>>>
>>>     echo $obj->2; /* parse error */
>>>
>>> Using a custom getter method as you posted above, IMO, seems
>>> easiest.
>>
>> echo $obj->'2'; should work (although I haven't tried it).
>
> That's still a syntax error; I tested in 5.4.12. However, I haven't
> bothered to check if it works in prior versions.
>

As I said - it was untested.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web