Initialize Class with Constant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nikolai.onken@gmail.com

    #1

    Initialize Class with Constant

    Hey,

    is it possible to define a constant - lets say

    define('CLASS_N AME','Shows');

    and then initialize the Shows class with

    $obj = new CLASS_NAME();

    This obviously doesn't work, but how would i have to do it to make it
    work?
    Best regards,

    Nikolai Onken

  • Markus L.

    #2
    Re: Initialize Class with Constant

    Am Sun, 22 May 2005 10:42:56 -0700 schrieb nikolai.onken@g mail.com:
    [color=blue]
    > Hey,
    >
    > is it possible to define a constant - lets say
    >
    > define('CLASS_N AME','Shows');
    >
    > and then initialize the Shows class with
    >
    > $obj = new CLASS_NAME();
    >
    > This obviously doesn't work, but how would i have to do it to make it
    > work?
    > Best regards,
    >
    > Nikolai Onken[/color]

    Try it this way:

    define('CLASS_N AME','Shows');
    $classname = CLASS_NAME;
    $obj = new $classname;


    or with eval:

    define('CLASS_N AME','Shows');
    $obj = eval('new ' . CLASS_NAME . '();');

    --
    -------------------------------------------------------
    Try this: SCA the Smart Class Archive for PHP

    -------------------------------------------------------

    Comment

    Working...