Re: One class, many methods: PHP4.x: Q's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/10/07, Micky Hulse <micky@xxxxxxxxxxxxx> wrote:
Hi,

This might be a real obvious question/answer... but I have been up all
night geeking on code, so my mind is kinda mushy -- please be kind. :)

I have a class called Randimg. Within that class, I have several
methods. Within a few of those methods, I use the below code snippet:

$_SERVER['DOCUMENT_ROOT']

What would be the best way to assign the above code to a global
variable/constant within the class?

Also, within each method, I am returning error strings... I would like
to create these as class constants... Or something... What is best way
to setup static strings within my class? Basically, I would like to have
these strings at the top of my class so potential users can easily
change the "settings." ;)

Lol, sorry is stoooopid questions... I am still kinda new to PHP OOP.

Many TIA's!
Cheers,
Micky

--
Wishlists: <http://snipurl.com/1gqpj>
    Switch: <http://browsehappy.com/>
      BCC?: <http://snipurl.com/w6f8>
        My: <http://del.icio.us/mhulse>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



As Rich pointed out you cannot have constants within a class in PHP4.
To answer the second part of your mail, one technique that I have seen
is something like the code below.

define('FOO_FILE_NOT_FOUND', 1);
define('FOO_FILE_NOT_READABLE', 2);
define('FOO_FILE_INVALID PATH', 2);

class Foo {
  function render() {
     if (! is_readable(...)) { return FOO_FILE_NOT_READABLE; }
  }
}

Another way that is nice is Solar's way of handling locales.
Basically it uses strings such as 'SOME_ERROR_MESSAGE' which is
populated by an include file that contains the actual value to it.  So
in this include file you create an array that contains key value pairs
of error codes and error messages.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux