Bhuwan Pandeya
Bhuwan Pandeya

Reputation: 3

PHP: class.object does not show print_r()?

I'm trying to print class object using print_r.

This is my index.php code

<?php 

if (isset($_POST['btnLogin'])){
    if (isset($_POST['username']) && !empty($_POST['username'])){
        $username=$_POST['username'];
    }else{
        $errusername="Enter Username";
    }

    if (isset($_POST['password']) && !empty($_POST['password'])){
        $username=$_POST['password'];
    }else{
        $errpassword="Enter Password";

    }
    if (isset($email) &&  isset($password)) {

        $user = new User();
        print_r($user);

    }


}

 ?>

This is user.class.php

<?php
class User{

    public $id,$name,$username,$password;

    public function login()
    {
        echo "this is function";

    }

}
?>

I want to print class object for eg: OBJECT([username=>this,password=>this]) It does not show any errors and does not show the print_r result.

Upvotes: 0

Views: 339

Answers (3)

sharaz ghouri
sharaz ghouri

Reputation: 53

you can use

echo "<pre>";

var_export( $user )

Upvotes: 1

Mauricio Florez
Mauricio Florez

Reputation: 1132

You are validating $email but declaring $username and other error assigning $password

if (isset($_POST['btnLogin'])){
    if (isset($_POST['username']) && !empty($_POST['username'])){
        $username=$_POST['username'];
    }else{
        $errusername="Enter Username";
    }
    if (isset($_POST['password']) && !empty($_POST['password'])){
        $password=$_POST['password'];
    }else{
        $errpassword="Enter Password";
    }
    if (isset($username) &&  isset($password)) {
        $user = new User();
        print_r($user);
    }
}

Upvotes: 2

jeprubio
jeprubio

Reputation: 18002

Change:

$username=$_POST['password'];

With:

$password=$_POST['password'];

As the $password var is not set the print_r is not executed.

Upvotes: 2

Related Questions