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


Groups > comp.lang.php > #8677

Re: question about class getters

From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: question about class getters
Date 2013-03-16 12:06 +0100
Message-ID <aqj211F6braU1@mid.uni-berlin.de> (permalink)
References <acaaecf6-a484-4603-8c21-6dad66988e18@c6g2000yqh.googlegroups.com> <khvh8s$13k6$1@yojimbo.hack> <045f80bf-c1fe-4ef0-8fcd-ab1de2ebdb09@7g2000yqy.googlegroups.com>

Show all headers | View raw


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.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web