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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:30:34+00:00 2026-06-03T03:30:34+00:00

don’t know better title for this, but here’s my code. I have class user

  • 0

don’t know better title for this, but here’s my code.

I have class user that checks form data when it’s instanciated but I get following errors/notices:

Notice: Use of undefined constant username - assumed 'username' in C:\Users\Jinxed\Desktop\WebTrgovina\app\m\Register\User.m.php on line 7

Notice: Use of undefined constant password - assumed 'password' in C:\Users\Jinxed\Desktop\WebTrgovina\app\m\Register\User.m.php on line 7

Notice: Use of undefined constant passwordc - assumed 'passwordc' in C:\Users\Jinxed\Desktop\WebTrgovina\app\m\Register\User.m.php on line 7

... and so on for every defined variable in user class.

Here’s the user class:

class User {
    function __construct(){
        $test = 'blah';
        $username; $password; $passwordc; $name; $surname; $address;
        $this->checkInput(array(username=>20, password=>20, passwordc=>20, name=>20, surname=>40, address=>40));
    }
    //array(formName=>CharacterLimit)
    private function checkInput($fields){
        foreach($fields as $field=>$limit){
            if($_POST[$field]=='' || strlen($_POST[$field])>$limit) $this->error[] = "$field must be filled in, and it must be less than or $limit characters long.";
            else $this->{$field} = $_POST[$field];
        }
    }
}

I don’t quite understand what’s the problem, I’ve tried first just creating variables and than from the main program calling checkInput method, but I get same error.

  • 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-03T03:30:35+00:00Added an answer on June 3, 2026 at 3:30 am

    You should be quoting the strings that you use as array keys:

    $this->checkInput(array(
        'username'=>20,
        'password'=>20,
        'passwordc'=>20,
        'name'=>20,
        'surname'=>40,
        'address'=>40));
    

    The documentation says:

    If you use an undefined constant, PHP assumes that you mean the name
    of the constant itself, just as if you called it as a string (CONSTANT
    vs "CONSTANT"). An error of level E_NOTICE will be issued when this
    happens. See also the manual entry on why $foo[bar] is wrong (unless
    you first define() bar as a constant).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know a better title but here is what im trying to do. I
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know why but I can't find a solution to this. I have 3
Don't know if there is a better way to do this, so that is
Don't really know how to formulate the title, but it should be pretty obvious
I don't know whether this is really possible, but I'm trying my best. If
Don't know how to explain it better but i'm trying to get a response
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a

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.