Reply to Re: How about const supporting array in future?

Your name:

Reply:


Posted by Yarco on 08/02/07 04:04

Yes, they could work if we do our effort.
We could add final keyword to forbidden someone to change this
class...

final class Date
{
private static $month_names = array(...);

public static getMonthName($i)
{
return $month_names[$i];
}
}

But const array would keep it simple.


On Aug 2, 11:49 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Yarco wrote:
> > Yes, it can be done like this.
> > But cause $MONTH_NAMES is variable, someone could change the value.
>
> > // Data.cls.php
> > class Date {
> > public static $MONTH_NAMES = array('January', ...);
> > }
>
> > // Plugin.php
> > Date::$MONTH_NAMES = null; // someone don't know the meaning of the
> > variable
>
> > // Template.php
> > print Date::$MONTH_NAMES[1]; // then your code doesn't work
>
> > On Aug 2, 11:01 am, Hendri Kurniawan <hckurnia...@gmail.com> wrote:
> >> On Aug 2, 12:55 pm, Yarco <yarc...@gmail.com> wrote:
>
> >>> Array is the very basic type in php i think. So why const keyword
> >>> doesn't support such defination grammar?
> >>> class Date
> >>> {
> >>> const char3 = array(1 => 'Jan', ...); // ??
> >>> }
> >>> So how can i do somthing like c++'s enum?
> >>> class Data
> >>> {
> >>> const Jan = 1;
> >>> //...
> >>> }
> >>> is poor if i want to chanslate number to month name.
> >> Well if you can't have const array, do a public static property
> >> instead
> >> class Data {
> >> public static $MONTH_NAMES = array('January', ...);
>

> >> }
>
> >> Hendri Kurniawan
>
> Make it private and don't change it in the class (requires PHP 5.x,
> which people should be on now - or at least soon).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

[Back to original 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

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