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 8284443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:06:17+00:00 2026-06-08T11:06:17+00:00

In php reading from here http://docs.php.net/manual/en/migration54.new-features.php It says, Class member access on instantiation has

  • 0

In php reading from here

http://docs.php.net/manual/en/migration54.new-features.php

It says,

Class member access on instantiation has been added, e.g. (new Foo)->bar().

I have a class and call its methods like below (as I cannot do what it says above!!),

$router = new RouterCore();
$method = $router->method;
$controller = new $router->controller();
$controller->$method();

What is the syntax for doing what is stated above when both of the class name and the method name exist as properties of another class? I have tried what is below;

$router = new RouterCore();
new ($router->controller())->$router->method(); // no go
new $router->controller()->$router->method(); // no go
new ($router->controller()->$router->method()); // no go
  • 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-08T11:06:19+00:00Added an answer on June 8, 2026 at 11:06 am

    You’re not following the syntax from the documentation.

    new ($router->controller())->$router->method();

    is not the same as

    (new $router->controller())->$router->method();

    In the first instance you are trying to perform new on the result of method(), however the second instance creates a new object from the result of controller() and then calls it’s method.

    Even then $router is not going to be a property of the controller, you need to evaluate $router->method() first and then use that as the method name.

    I suspect what you actually want is

    (new $router->controller())->{$router->method()}();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading up on Stored Procedures & MYSQLi from here http://php.net/manual/en/mysqli.quickstart.stored-procedures.php and other
When learning new languages such as C++ from PHP, does reading other language snippets
I'm having troubles reading from this api http://api.xhanch.com/islamic-get-prayer-time.php?lng=67&lat=24&yy=2012&mm=7&gmt=5&m=json Here's my code: new Read().execute(sunrise); public
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class
It's clear from reading through threads that I can call a PHP function using
I'm reading in a plist from a web server, generated with some php. When
I'm reading a PHP book where the author says that symbols should be avoided
I am very new to programming in general, while reading about PHP I saw
I'm reading some XML with PHP and currently using the DOMDocument class to do
I am completing a tutorial which can be found here...http://www.elated.com/articles/cms-in-an-afternoon-php-mysql/ I am having problems

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.