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

  • Home
  • SEARCH
  • 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 8205413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:13:48+00:00 2026-06-07T08:13:48+00:00

I need to call a static method of a class, but I only have

  • 0

I need to call a static method of a class, but I only have a classname, not an instance of it. I am doing it this way.

$class = new "ModelName";
$items = $class::model()->findAll();

It works on my computer, but when I move to the server, it throws an unexpected T_PAAMAYIM_NEKUDOTAYIM, so I think it actually expects model to be a variable instead of a method.

PS: If it helps, it’s Yii framework, so if there’s another way to call the find() functions, it’s ok to me.

Thanks in advance

  • 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-06-07T08:13:51+00:00Added an answer on June 7, 2026 at 8:13 am

    This is because your server runs a version of PHP earlier than 5.3.0, in which this syntax is not supported.

    From the documentation on the scope resolution operator:

    As of PHP 5.3.0, it’s possible to reference the class using a
    variable. The variable’s value can not be a keyword (e.g. self, parent
    and static).

    In any case, you can always use call_user_func:

    $class = "ModelName"; // the "new" in your example was a typo, right?
    $items = call_user_func(array($class, 'model'))->findAll();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case where I need to call a (non-static) method in
I have a non-static C# class with some instance methods, which I need to
I have a generic class that has a method 'Call' on it with a
I have an object pool, and I need to call a delegate method OnFree(),
I have a generic class that I need to constrain to only value types
For example, let's say that in Android, I need to call the static method
How do I call a static method? I want to call this from a
I need to create a delegate to a non-static method of a class. The
I need to call a method and pass an object from my custom UITableViewClass
I need to call some jQuery .load() function from flash. i Use this: import

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.