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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:13:39+00:00 2026-05-29T16:13:39+00:00

All, I’m a fairly new and I mostly studied OOP with Java. With this

  • 0

All,

I’m a fairly new and I mostly studied OOP with Java.

With this said, here is the relevant code:

Model.php

class Model{ // Object that represents a connection to the relevant db table
        private $db; //contains the identifiers of the db
        private $dao;

        function createRecord1(){
            return $this->dao->createRecord();
        }
    }

User_Model.php

class Model_user extends Model {
        function __construct($db){
            $this->db=$db;
            $dao=DAO_DBrecord::createUserDAO($this->db);//  This is a static function that calls the DAO constructor with a 'user' table name parameter
            $this->dao=$dao;
        }
    }

Then in Controller_Register.php, I have this code:

//Some other code
$db=DB::createDB();
$userModel=new Model_User($db);
$userID=$userModel->createRecord1();
//Some more code

This yields the error message I have in the title. The line return $this->dao->createRecord(); inside Model.php causes the error.

There is no error if the function createRecord1() is placed in Model_User instead of in the parent class – but then of course I would have to duplicate it in other children.

What am I doing wrong?

  • 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-05-29T16:13:45+00:00Added an answer on May 29, 2026 at 4:13 pm

    The “same” code in Java would result in the same errors. $db and $dao are specified as private class members of Model, so are not available for you to manipulate directly in classes which extend Model. Try changing

    class Model {
            private $db;
            private $dao;
            ...
    

    to

    class Model {
            protected $db;
            protected $dao;
            ...
    

    You can read more about this in the PHP documentation:

    Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inherited and parent classes. Members declared as private may only be accessed by the class that defines the member.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
All the code/commands below are part of a PHP script that processes images from
All, This is a follow up for my question here . My setup: Visual
all! What is wrong with this code? I cannot understand what I am doing
All I want is to update an ListViewItem's text whithout seeing any flickering. This
All, Say I have the following bit of code: select: function(start, end, allDay) {
All, I have just reinstalled Java on my machine because I found I had
All, My classpath has been set to the following folder: CLASSPATH = .;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program
All! I found strange code in LinkedBlockingQueue: private E dequeue() { // assert takeLock.isHeldByCurrentThread();

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.