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

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

 



Micky Hulse wrote:

I assume setting basic strings (i.e. "settings") for my error messages would be best done via:

class Randimg
{

var $msg_1 = 'This is a string';
var $msg_2 = 'This is another string';

function rand_img() { echo $this->msg_1; }
function foo() { echo $this->msg_2; }

}

I don't know if that's the *best* way, personally I'd not really do it like that, but no-one can tell you it is 'right' or 'wrong' because it depends on your application. For example if you only have a handful of possible error messages (say < 10) then there is nothing inherently wrong with the above approach.

If you're talking about lots of error messages then under PHP 4 I'd declare them as consts in a required() file.

define('APP_ERROR_1', 'This is an error message');

Then just use APP_ERROR_1 in the methods that need it. It's a bit messy because you are creating consts all over the place, but it's an option for you and at least it keeps them all in a single file and out of the header of your class.

Another way might be to create a specific class that does nothing but handle error messages / responses, then call that.

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

--
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