Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:05:51+00:00 2026-05-22T19:05:51+00:00

Now I am working with yii framework and I’d like to wrote something like

  • 0

Now I am working with yii framework and I’d like to wrote something like this:

protected static $model = "Customer";
...
public function actionIndex() {
    $model::model()->find(...

Now it works:

protected static $model = "Customer";
protected static $model_obj;
...
public function __construct($controller, $id) {
    $this->model_obj = new self::$model;
...
public function actionIndex() {
    $model_obj::model()->find(...

but creating object for access static member is a bad thing.
how to avoid it?

getClass takes object as first parameter and it is not suitable for this purpose

google say:

$a = constant($myClassName . "::CONSTANT");
$b = call_user_func(array($myClassName, "static_method"));

it looks like a horrible peace of shit. using this may make many troubles. another solution?

oh! my problem was another:

$controller::$NAME::model() // error

$controller_name = $controller::$NAME
$controller_name::model() // good

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:05:52+00:00Added an answer on May 22, 2026 at 7:05 pm
    class foo
    {
      public static function bar()
      {
        return 42;
      }
    }
    
    // class name as string
    
    $class = 'foo';
    
    var_dump($class::bar()); // 42
    
    // method name as string
    
    $method = 'bar';
    
    var_dump(foo::$method()); // 42
    
    // class AND method names as strings
    
    var_dump($class::$method()); // 42
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm now working with code that looks like this public String getName(User user) {
I am now working on a program for Android which is something related to
Thanks to Code Poet, I am now working off of this code to parse
I just read this blog post and it stated that: Google is now working
My nested model form is now working, but I am having trouble displaying the
this may come as pretty odd but I'm now working on a membership based
I am now working with Android TabWidget. I build this TabWidget based on http://mobileorchard.com/android-app-development-tabbed-activities/
I am right now working with this image upload from HERE . Instead of
I am now working on changing android theme style at runtime, when the user
I have now been working as a web developer for two weeks and have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.