FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » question about class getters
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: question about class getters [message #180741 is a reply to message #180735] Sat, 16 March 2013 11:06 Go to previous messageGo to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma:
Senior Member
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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Will this set or get a SESSION variable?
Next Topic: Fatal error!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 01:35:51 GMT 2024

Total time taken to generate the page: 0.06155 seconds