1

I basically know php but i am new to all that classes-stuff. For now - love it. Here is my problem:

I'm writing a class to do all that stuff around the account-managements. (e.g. create new account, get account details, check if account exists .... ) Within that class i need to do some MySQL-requests. Therefor i i'm using the medoo-class (http://www.medoo.in).

class acc{

// Attributes
public static $account;
public $pw;
protected $error;

public function acc_exist() {
    $database = new medoo();

    $acc_count = $database->count("table_accounts", ["column_account" => acc::$account]);

    if ($acc_count == 0)  {return true;} else {$this->error .= "Account exists already!";};
}};

Please note the line:

$database = new medoo();

and

    $acc_count = $database->count("table_accounts", ["column_account" => acc::$account]);

here i bring in medoo. And ["column_account" => acc::$account] acctually works. As i read in some other posts, i made $accounts public static.

now i call my class like this:

$my_acc = new acc();
$my_acc->account = 'Luci';
$my_acc->acc_exist();

i need to work like that. Doing some acc($account) is difficult in context of the rest of my code.

But as i expected, i get an error:

Strict Standards: Accessing static property acc::$account as non static

clear to my that static holds the var's value. so i will need some other way. Anyone got an idea?

best, Lox

2
  • You have a typo in the code $accout should be $account I think Commented Apr 26, 2015 at 0:00
  • you are right - but that is not the Problem. just changed the Variables for better understanding. was like acc tbacc acccnt before. Commented Apr 26, 2015 at 0:13

3 Answers 3

1

I don't think you need to have $account as static, that wouldn't make sense with the way you're probably going to be using this code, try having public $account; and then use ["column_account" => $this->account]

So:

class acc{

// Attributes
public $account;
public $pw;
protected $error;

public function acc_exist() {
    $database = new medoo();

    $acc_count = $database->count("table_accounts", ["column_account" => $this->account]);

    if ($acc_count == 0)  {return true;} else {$this->error .= "Account exists already!";};
}};

Here's more information on how to use static properly: Static Keyword in PHP

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

4 Comments

thx for your answer. Sorry but that won't work. The line $database->count("table_accounts", ["column_account" => $this->account]); refers to $database als object of medoo-class. That means, if you go with $this->account, you would call for a var $account in the medoo-class and not in the acc-class. That is the problem
Did you try the code? You're calling a method count of the $database object (which is of the medoo class), and you're passing parameters to the method, the first is a string, the second is an associative array, with a key value pair, the value being the account property of the current object $this (which is of the acc class). It should work.
hmm... that sounds very logical. wait a minute. i'll try again. maybe i mixed up something else.
player of the match! you are right. Guess i just thought way to complicated with that.
0

You are calling a variable that doesn't exist.

You declared $accout as public and static.

But you attempt calling $account.

Replace:

$my_acc->account = 'Luci';

With:

$my_acc->accout = 'Luci';

1 Comment

thanks for your quick answer - please read my last comment on the question. Changed that.
0

Vex is right. Take off the static keyword and use ["column_account" => $this->account] instead.

Bests,

B.

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.