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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:14:10+00:00 2026-06-01T17:14:10+00:00

I successfully instantiated the object class but I can’t figure out how to call

  • 0

I successfully instantiated the object class but I can’t figure out how to call a function.
Here is my PHP code:

$obj = new router();
class router{

public function __construct(){
    if($_SERVER['REQUEST_METHOD'] == 'GET'){
        echo "GET";
        $page = 'index';
        $funct = 'myfuncempty';

        if (!empty ($_GET)){
            $page = $_GET['page'];
            $funct = $_GET['func'];
        }
        $obj = new $page(); //instantiating object with get from class
        $obj->funct;
    }
    else{
        echo "POST";
    }

}

}
class index{

public function __construct(){
    echo "hello I'm index";
}
public function myfunc(){
    echo "yo";
}

public function myfuncempty(){
    echo "empty get";
}
}

class login{
public function __construct(){
    echo "hello I'm login";
}

public function loggedin(){
    echo "you're logged in";
}

public function loggedinempty(){
    echo "its empty";
}
}

And this is the HTML form that I use to pass variables via GET:

<html>
<head></head>
<body>
<form action="index.php" method="POST"><input type ="text" name="page" id="page" /><input type="submit" /></form>
<form action="index.php" method="GET">Page:<input type="text" name="page" id="page" />Function:<input type="text" name="func" id="func" /><input type= "submit" />
</body>
</html>

When I type index in for page and myfunc in for function, I get this response:

GEThello I'm login Notice: Undefined property: login::$funct in /home/cr47/public_html/final_project/index.php on line 27

So, it is passing the ‘page’ correctly and instantiating the object but it is not correctly calling the myfunc function.
Any ideas?

  • 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-01T17:14:11+00:00Added an answer on June 1, 2026 at 5:14 pm

    Replace $obj->funct; with $obj->$funct();

    But be careful. You shouldn’t let your users instantiate arbitrary classes. At least use a whitelist or require them to be a subclass of some custom class only used by your classes which are safe (i.e. no public methods that do anything a user shouldn’t be able to do).

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

Sidebar

Related Questions

I have learned that we can't instantiate an abstract class. But today i tested
I can successfully connect to the database with my datacontext object. I am able
Successfully used jquery-infinite-carousel in the past but for my current project I need it
I successfully compiled ActionBarSherlock in Eclipse. But I get 75 errors when I use
I successfully installed the latest QuantumGrid from DevExpress, but I've never worked with this
Where I'm stuck is the right parameter syntax to instantiate an object using PHP's
I'm trying to instantiate an object using a class in an external jar. This
I hate to introduce Unit-tests into a legacy code base, but I have to.
I'm fairly new to CodeIgniter, and am trying to figure out something I feel
I am working on a Configuration Loader class so that I can change the

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.