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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:04:55+00:00 2026-05-30T20:04:55+00:00

This is my user class: <? require_once(dirname(__FILE__).’/DB.class.php’); require_once(dirname(__FILE__).’/Model.class.php’); class Benutzer extends Model { private

  • 0

This is my user class:

<?
require_once(dirname(__FILE__).'/DB.class.php');
require_once(dirname(__FILE__).'/Model.class.php');

class Benutzer extends Model
{
    private $id;
    private $loginName;
    private $loginPassword;
    private $eMail;
    private $rights;
    private $mailchange;
    private $name;
    private $vorname;
    private $matrikelnr;
    private $gruppe;

    /**
     * @TODO PhpDoc
     */
    protected function __construct($id = null)
    {
        if ($id !== null)
            $this->load($id);
    }

    /**
     * @TODO PhpDoc
     */
    public static function factory($id = null)
    {
        if ($id !== null && is_integer($id)){
            return new Benutzer($id);

        } else {
            return new Benutzer();
        }
    }
//getter and setter...
}

This is the abstract class that is inherited by the user class:

<?php

require_once(dirname(__FILE__).'/RowDataGateway.interface.php');

abstract class Model implements RowDataGateway
{

    public function getParameters()
    {
        return get_object_vars($this);
    }

    /**
     * @TODO PhpDoc
     */
    public function setParameters(array $values, $override = true)
    {
        foreach ($values as $key => $val) {
            if ($override){
                if (property_exists(get_class($this), $key))
                    $this->$key = $val;
            }
            else {
                if (property_exists(get_class($this), $key) && !isset($this->key))
                    $this->$key = $val;
            }

        }
    }

    /**
     * @TODO PhpDoc
     */
    public function load($id, $override = true)
    {
        $res = QueryBuilder::selectQuery($this);
        $result = DB::getInstance()->query($res['query'], array('id' => $id));
        $this->setParameters($result, $override);
        return $this;
    }


    /**
     * @TODO PhpDoc
     */
    public function save()
    {
        if (isset($this->id)){
            $res = QueryBuilder::updateQuery($this);
            if (DB::getInstance()->update($res['query'], $res['params'])){
                return $this;
            }
        }
        else {
            $res = QueryBuilder::insertQuery($this);
            if ($id = DB::getInstance()->insert($res['query'], $res['params'])){
                $this->id = $id;
                return $this;
            }
        }
        return false;
    }

    /**
     * @TODO Implement
     */
    public
    function delete()
    {
    }
}

Everytime i call the $obj->getParameters() function i get an empty array (in the foreach):

        public static function insertQuery(Model $obj)
    {
        //INSER INTO classname (field1,field2,field3) VALUES (val1,val2,val3)
        $vars = null;
        $query = 'INSERT INTO `'.strtolower(get_class($obj)).'` (';
        foreach ($obj->getParameters() as $key => $val) {
            if ($key !== 'id')
                $query .= $key.',';
        }
        $query = substr($query, 0, strlen($query) - 1);
        $query .= ') VALUES (';
        foreach ($obj->getParameters() as $key => $val) {
            if ($key !== 'id'){
                $query .= ':'.$key.',';
                $vars[':'.$key] = $val;
            }
        }
        $query = substr($query, 0, strlen($query) - 1);
        $query .= ')';
        return array('query' => $query, 'params' => $vars);
    }

I’ve already debugged the code and the right object is given to the function!?

Where is my mistake?

FMK

  • 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-30T20:04:56+00:00Added an answer on May 30, 2026 at 8:04 pm

    That’s because the properties of the child class are not visible from the method. You have two options:

    • Move the method to the child class.
    • Turn the visibility of the properties from private into protected.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract =
This is my code: <?php require_once '../../../jq-config.php'; // include the jqGrid Class require_once ABSPATH.php/jqGrid.php;
I have a two models set up like this: class User < ActiveRecord::Base #
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have this Class: public class User { public string id{ get; set; }
Having a snippet like this: import yaml class User(object): def __init__(self, name, surname): self.name=
Im using DataContractJsonSerializer to serealize this class: public class User { public string id
Can't wrap my head around this... class User < ActiveRecord::Base has_many :fantasies, :through =>
This is my code: class Friend < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name =>

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.