"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message 
news:1275678975.2217.83.ca...@localhost...
> On Fri, 2010-06-04 at 22:07 +0300, Tanel Tammik wrote:
>
>> Hi,
>>
>> define('MYCONST', 'something');
>>
>> $my = 'my';
>> $const = 'const';
>>
>>
>> is it possible to get the value of MYCONST using variables $my and 
>> $const_
>>
>> Br
>> Tanel
>>
>>
>>
>
>
> I don't really see how you can? The only correlation at all is that the
> two variables use the same letters combined as their values as the name
> of the constant but in a different case. Variables and constants in PHP
> are case-sensitive.
>
> Why are you trying to do this anyway? Perhaps there's a better way than
> what you are trying to do.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

<?php
define('PERFIX', 'dbperfix_');
define('DB_MYTABLE', PERFIX . 'mytable');

abstract class Database {
  private static function table_name() {
    $table_name = strtolower(get_called_class());
    return constant('DB_' . strtoupper($table_name));
  }

  public static function return_query() {
    return "select * from " . static::table_name() . " where 
something='value'";
  }
}

class MyTable extends Database {
}

echo MyTable::return_query();
?>

i know i could just do return PERFIX . $table_name. -  i'm using it that 
way. i was just curious if the other way is possible. might come handy some 
day!

Br
Tanel 



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

Reply via email to