0

I am trying to make a class that simply holds and retrieves simple string variables.

Here is what i have in the User.php file (the class)

class User {

//private variables
private $u_s;
private $p_w;

public function _construct($u_s, $p_w){
    $this->u_s = $u_s;
    $this->p_w = md5($p_w);
}

function getUsername(){
    return $this->u_s;
}

function getPassword(){
    return $this->p_w;
}

}

and here is the index.php file

    <?php
       include("User.php");

       $u = new User("Jake", "pass");
       echo $u->getUsername() + "\n" + $u->getPassword();
    ?>

Why does this not work?

2 Answers 2

2

You mistyped __construct. There should be two underscores, not one.

Sign up to request clarification or add additional context in comments.

Comments

1

Concat char in PHP is . (dot), not + (plus) sign:

<?php
include("User.php");

$u = new User("Jake", "pass");
echo $u->getUsername() . "\n" . $u->getPassword();

And as adpalumbo said you mistyped __construct

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.