You are here: Re: PHP, OOP, and Constants « PHP Programming Language « IT news, forums, messages
Re: PHP, OOP, and Constants

Posted by Steve on 12/18/07 20:11

"boris" <bkerzner@gmail.com> wrote in message
news:4a701169-914c-4fd1-b38f-89f630260052@a35g2000prf.googlegroups.com...
> Willem - thanks for the suggestions. I guess there's no easy way to do
> it. I'm using CakePHP, however, and it seems adding
> define('constname','constvalue') statements to /cake/app/config/
> core.php makes the constants universally available. These constant
> definitions belong, ideally, in a separate configuration file, but,
> for now, this is an 'okay' solution.

i have a 'site' static class wherein i define paths for the rest of the
site. site.cfg.php is the name of the script that sets all of the paths up.
it would look something like:

site::initialize(); // instanciate global static class
site::$myPath = '/cake/app/config/';

the site class would look something like:

class site
{
public $myPath = '/';
private __contruct();
public initialize();
}

at the beginning of each page on my site, i have this:

<?
require_once 'site.cfg.php';
?>

i don't think that defining a path in a class is a wise thing to
do...especially when there are multiple classes that my need to be changed
in order to get your site up and running...such as a db class (changing the
connection details, etc.). that's why i do it all in one script,
site.cfg.php.

as for constants in objects...you can do that in php 5. though it's not a
real namespace, you get similar behavior. just define your variable/constant
in the class as:

const myPath = '/cake/app/config/';

i do this with image types:

class imageTypes
{
const GD = 0;
const GIF = 1;
const JPG = 2;
const PNG = 3;
}

this is far from arbitrary...and is accessed as you say, imageTypes::PNG.
though i haven't tried - in this example, i don't need to - to
inherit/extend a class with constants, i'm almost positive it would retain
them, just as java and other oop-enabled languages do. i'd be interested in
what you find out...i usually rtfm when i need to, and i just haven't run
across the need to anwer this one definitively yet.

cheers.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация