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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:17:28+00:00 2026-06-01T18:17:28+00:00

When TestPage.php is run in browser, ‘trying to create new obj…’ is echo’d, but

  • 0

When TestPage.php is run in browser, ‘trying to create new obj…’ is echo’d, but nothing else. Is the constructor not getting called?

This isn’t the full code for either class, but hopefully it’s enough for someone to tell me where I’m going wrong…

TestPage.php

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/plain; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        class MyClass {
        $api_key = 'somestring';
        $username = 'username';
        echo 'trying to create new obj...';
        $myObj = new MyClass($api_key, $username);
        echo 'new obj created...';

    ...
        ?>
    </body>
</html>

MyClass.class.php

<?php
class MyClass {
    protected $_api_key;
    protected $_username;


    public function __construct($api_key, $username) {
        echo 'entered constructor...';
        $this->_api_key = $api_key;
        $this->_username = $username;
        echo 'leaving constructor...';
    }

    ...
}
?>
  • 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-01T18:17:30+00:00Added an answer on June 1, 2026 at 6:17 pm

    You need to actually define it as a class. That would look like:

    class MyClass {
        protected $_api_key;
        protected $_username;
    
    
        public function __construct($api_key, $username) {
            echo 'entered constructor...';
            $this->_api_key = $api_key;
            $this->_username = $username;
            echo 'leaving constructor...';
        }
    }
    

    Just placing the code you have in a file and naming it won’t do anything on its own.

    Additionally, you’ll need to include that file if you haven’t already. Something like:

    include 'MyClass.class.php';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with some PHP code I'm trying to use. I keep
I'm trying to create a test fixture using Fitnesse framework, and I want to
I have this test page: http://www.problemio.com/problems/problem.php?problem_id=305 I am trying to make the form towards
I have this test page: http://www.problemio.com/index_new.php and I am trying to make some jQuery
I am working on this test page: http://problemio.com/test.php What I am trying to do
I'm trying to deploy an PHP application which is written with Zend Framework to
Here is the test page: http://grozav.com/test.php I'm trying to add a jquery function to
From PHP, I'm having trouble getting the browser to delete a cookie. To chase
I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))
Aspx Page: $(document).ready(function() { $(#btnn).click(function() { $.ajax({ type: POST, url: TestPage.aspx/emp, data: {}, contentType:

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.