Re: Class declaration, constants and array

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

 



Marek wrote:
> php5 class {
>
>     const _SOMETHING_ = 'test';
>
>     private $abc=_SOMETHING_;      // fails, well actually anything fails
> similar to this.
>     var $test=$test2;                    // also fails
>
> So since I can not use dynamic var assignment within the class
> declaration,
> what are some of the easy solutions to this ? without making anything
> global
> to the script ?

private $abc = 'test';

Now, if you NEED to use some kind of constant, you could write a PHP
script to create your class definition, and then you'd have what you
want...

That can't be too hard, since I once had a guy I was working for who
thought he had laid out a couple months' work for me, only I was done in 3
days, since it was all building classes to mirror MySQL table/fields in a
very brain-dead straight-forward fashion, and I wrote code like this, and
I don't even really grok PHP classes all that well.

Not that I think that made for a particularly good Design, but that's what
he wanted, so who am I to say?  But I sure wasn't gonna sit there typing
like a monkey when I could just script the same thing.

Or I guess you could hack something up with eval() if you really worked at
it...  That would be pretty nasty code, though, I think.

It would be nice if PHP allowed constants there, but it doesn't, so there
it is.

-- 
Like Music?
http://l-i-e.com/artists.htm

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