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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:14:54+00:00 2026-06-01T21:14:54+00:00

I am new to php and OOP in general, so have decided to turn

  • 0

I am new to php and OOP in general, so have decided to turn my existing site in an oo php one to gain some experience.
Here is the issue I am currently facing.

I have a class Normaluser which is extending from User. Inside the User class is a login method which returns an object containing an array of the Users class’ properties.

class NormalUser extends User {

public function __construct($loginarray){
    $email = $loginarray['email'];
    $pass = $loginarray['pass'];

    var_dump ( parent::login($email,$pass) );
    //return parent::login($email,$pass)
}
}

When doing a var_dump (as above) I get

bool(false) object(User)#8 (4) 
{ ["user_id"]=> string(1) "1" ["first_name"]=> string(7) "Melanie" ["last_name"]=> string(6) "Janson" ["user_level"]=> string(1) "1" }

Yet after calling the code in my login.php page :

$postdata = User::mysqli_array_escape($_POST);      

    $email = $postdata['email'];
    $pass = $postdata['pass'];

    $userstart = new NormalUser($postdata);
    var_dump($userstart);

I would think that calling $userstart as a new NormalUser object would return the correct variables, yet when I do a var_dump (as written in above) I receive the following :

object(NormalUser)#5 (4) 
{ ["user_id"]=> NULL ["first_name"]=> NULL ["last_name"]=> NULL ["user_level"]=> NULL } 

I do not understand where I have gone wrong, If anyone would be able to point me in the right direction I would be greatly appreciative.

Thank you.

EDITED : added user.php login method as requested

    public static function login($email, $pass) {
    global $database;
    $sql = "SELECT user_id, first_name, last_name, user_level FROM users WHERE (email='$email' AND pass=SHA1('$pass')) AND active IS NULL LIMIT 1";
    $results = self::find_by_sql($sql);
    //var_dump($results);
    if (!empty($results)) {

        return array_shift($results);
    } else {
        return false;
    }

}
  • 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-01T21:14:56+00:00Added an answer on June 1, 2026 at 9:14 pm

    The problem is that you are returning an object in the constructor. This is not how constructors work.

    I have two options for you:

    1. Either you create a static method that returns a NormalUser instance (instead of using the constructor):

      // In your NormalUser class.
      static function createNormalUser($loginarray) {
        $email = $loginarray['email'];
        $pass = $loginarray['pass'];
        return parent::login($email,$pass);
      }
      
    2. Or you stick with the constructor but instead of returning an object instance, you assign its attributes to the $this instance:

      function __construct($loginarray) {
        $email = $loginarray['email'];
        $pass = $loginarray['pass'];
        $temp = parent::login($email,$pass);
      
        $this->user_id = $temp->user_id;
        // etc...
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to OOP (and also in PHP programming), and I have some
I am new to php oop, I have a some idea re Classes but
I'm a new guy in PHP OOP concepts. One of the first things that
I'm new to using OOP in PHP (And in general) and I had a
I've trying to learn PHP OOP and have made some research on how to
I have been recently learning some OOP PHP and seem to have run into
I am new to OOP in PHP (normally write software). I have read that
I'm quite new to PHP OOP and I have a question regarding a simple
I'm very new with PHP and OOP techniques. So I have no problem creating
I'm new to php oop.here i wanted to do database connectivity with singleton class

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.