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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:05:23+00:00 2026-06-18T00:05:23+00:00

I’m new in PHP development but I have experience in Java development. In java

  • 0

I’m new in PHP development but I have experience in Java development. In java we can pass an object of a classA to classB. Then in classB we have access to methods of classA. I’m looking for something like this in PHP.

In my test project, I have a Vote class.

    <?php

class Vote {    
    private $DeviceID;
    private $FullName;
    private $Rate;
    private $Comment;
    private $PublishTime;

    public function __construct($deviceId, $fName, $rate, $comment) {
        $this->DeviceID = $deviceId;
        $this->FullName = $fName;
        $this->Rate = $rate;
        $this->Comment = $comment;

        if(function_exists('date_default_timezone_set'))
            date_default_timezone_set('Asia/Tehran');
        $date = new DateTime();
        $this->PublishTime = $date->getTimestamp();
    }

    public function getDeviceID() {
        return $this->DeviceID;
    }

    public function getName() {
        return $this->FullName;
    }

    public function getRate() {
        return $this->Rate;
    }

    public function getComment() {
        return $this->Comment;
    }

    public function getPublishTime() {
        return $this->PublishTime;
    }

    public function setDeviceID($deviceId) {
        $this->DeviceID = $deviceId;
    }

    public function setFullName($name) {
        $this->FullName = $name;
    }

    public function setRate($rate) {
        $this->Rate = $rate;
    }

    public function setComment($comment) {
        $this->Comment = $comment;
    }

    public function setPublishTime($publishTime) {
        $this->PublishTime = $publishTime;
    }

    public function toString() {
        echo '<p><b>Device ID:</b>'.$this->getDeviceID().'<br />';
        echo '<b>User Name:</b>'.$this->getName().'<br />';
        echo '<b>Rate:</b>'.$this->getRate().'<br />';
        echo '<b>Comment:</b>'.$this->getComment().'<br />';
        echo '<b>Time:</b>'.$this->getPublishTime().'<br /></p>';
    }
}
?>

I have another class for reading from and writing to database.

<?php
    require_once 'class.vote.php';

class DBHandler {
    private $DB_HOST = "localhost";
    private $DB_USER = "root";
    private $DB_PASS = "";
    private $DB_NAME = "test";
    private $mysqli;

    public function __construct() {
        // CONNECT TO THE DATABASE
        $this->mysqli = new mysqli($this->DB_HOST, $this->DB_USER, $this->DB_PASS, $this->DB_NAME);
        if (mysqli_connect_errno()) {
            throw new Exception("Unable to connect to the database. Error number: " . $this->mysqli->connect_errno);
    }
    }

    public function __destruct() {
        //We are done with the database. Close the connection handle.
        $this->mysqli->close();

        echo 'DBHandler closed';
    }

    public function writeToDB(Vote $vote) {
        $query = "INSERT INTO vote (DeviceID, FullName, Rate, Comment, PublishTime)
            VALUES ('$vote->getDeviceID()', '$vote->getName()', '$vote->getRate()',
                '$vote->getComment()', '$vote->getPublishTime()')";
        $result = $this->mysqli->query($query);
        echo '$result';
        /* free result set */
        $result->free();
    }
}
?>

My problem is writeToDB(Vote $vote) function. When I run the project following errors will be displayed. Any suggestion would be appreciated. Thanks

Notice: Undefined property: Vote::$getDeviceID in F:\Software\NetBeans\xampp\htdocs\PHPAndroidAPI\class.dbhandler.php on line 32

Notice: Undefined property: Vote::$getName in F:\Software\NetBeans\xampp\htdocs\PHPAndroidAPI\class.dbhandler.php on line 32

Notice: Undefined property: Vote::$getRate in F:\Software\NetBeans\xampp\htdocs\PHPAndroidAPI\class.dbhandler.php on line 32

Notice: Undefined property: Vote::$getComment in F:\Software\NetBeans\xampp\htdocs\PHPAndroidAPI\class.dbhandler.php on line 33

Notice: Undefined property: Vote::$getPublishTime in F:\Software\NetBeans\xampp\htdocs\PHPAndroidAPI\class.dbhandler.php on line 33

============

Update

I’m using following code in order to test my code:

<?php
    require_once 'class.vote.php';
    require_once 'class.dbhandler.php';

    $deviceId = $_GET["p1"];
    $fName = $_GET["p2"];
    $rate = $_GET["p3"];
    $comment = $_GET["p4"];

    try {
        // Create Vote object based on parameters
        $objVote = new Vote($deviceId, $fName, $rate, $comment);
//        $objVote->toString();

        $objDBHandler = new DBHandler();
        $objDBHandler->writeToDB($objVote);

    } catch (Exception $e) {
        die("There was a problem: " . $e->getMessage());
    }

?>
  • 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-18T00:05:24+00:00Added an answer on June 18, 2026 at 12:05 am

    As far as I can tell, functions do not work inside “double quotes”, only variables. So, PHP are looking for a $vote->getDeviceID variable instead of a $vote->getDeviceID() function. You should change your SQL to ... VALUES ('".$vote->getDeviceID()."', ... so the functions are outside the quotes.

    Also, you should care about SQL injection specially when data comes from user input.

    • 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&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.