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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:09:55+00:00 2026-06-13T11:09:55+00:00

I have some classes set up as this, where -> means ‘extends’: DBObject ->

  • 0

I have some classes set up as this, where -> means ‘extends’:

DBObject -> Article -> Activity

DBObject contains a generic __construct to easily load my objects from the database (hence DataBaseObject).

Article overrides this __construct, for some specialized constructor behaviour.

Activity does not implement any __construct, as it can be handled by its superclass’ __construct (Article::__construct).

However, for some reason, if I call

$activity = new Activity($args);

It ends up in DBObject::__construct, and passes Article’s one all together. I always thought that calls on a subclass were supposed to travel up the subclass line one class at a time. Am I mistaken in thinking that?

EDIT: Here’s a code snippet: http://pastebin.com/SXpSNVMm. I removed all non-necessary code. I’m calling it like this:

$userId = 60;
$title = "TestTitle";
$contents = "Lorem ipsum dolor sit amet";
$date = 1356173771;

echo "creating new activity\n";
$a = new Activity($userId, $title, $contents, $date);

Placing echo’s in the constructors revealed that Article::__construct() was not used and it went right to DBObject::__construct().

Edit 2: This is a version that should be working properly: http://ideone.com/VJzdI3 . I’m using PHPUnit for testing. This is the output if i run with PHPUnit:

creating new activity 
DBObject constructed called 
QUERY: 60 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '60' at line 1

The latter means it’s trying to initialize it using meekrodb; That should only happen if i call new on a subclass of DBObject with something other than null or an array. However, since Article should override __construct, that one should be called first.

  • 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-13T11:09:56+00:00Added an answer on June 13, 2026 at 11:09 am

    Your understanding is correct: with the setup you describe creating a new Activity would definitely “defer” to Article::__construct. If it does not then your description and the actual code have to differ somewhere. PHP has its more than fair share of bugs, but this is a very simple scenario to attribute the surprising behavior to buggy code.

    If you still think there is nothing wrong with the code, please post a working sample on an online codepad like htpp://ideone.com that exhibits the issue.

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

Sidebar

Related Questions

I have some classes which extends a superclass, and in the JSP I want
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have some classes that are used for Styling and all of them display
I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
I have some classes that, for one reason or another, cannot be or need
I have some classes in my app that don't require an ID to be
I have some classes as below, i have implemented the Equals(Object) method for almost
I have some classes(call it Class A) which I would like to unit test
I have some classes which are parameterized via their constructor. I need to provide
In one of my projects, I have some classes that represent entities that cannot

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.