2

I am stuck part of this code.. I tried to call my static table variables but I can't.

Methinks I have very simple problem but.. effective and harmful for my project.

my class:

<?php

public $table;

class Functions
{
    public function ehe()
    {
        return $table[4];
    }
}

?>

my system.php file:

    $fn = new Functions();

    /* static tables */
    $table  = array(
                    0 => 'account.account',
                    1 => 'player.player',
                    2 => 'auction_house.items',
                    3 => 'auction_house.admin',
                    4 => 'auction_house.store',
                    5 => 'auction_house.styles',
                    6 => 'auction_house.logs',
                    7 => 'auction_house.coupons',
                    );

my index file(example): (connected with system.php & classes)

echo $fn->ehe;

my error:

Notice: Undefined property: Functions::$ehe in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\.......php on line 178

A Little second question: Also I have 2 classes. 1: Functions class. (Include query processings etc.) 2: MySQL connect class. I want to connect this two classes for queries. How is this possible? ..

2
  • 1
    Well $table is out of scope in the ehe() method Commented Sep 21, 2013 at 21:40
  • $table is out of scope, as Mark said. Also you're accesing a property here echo $fn->ehe which is a variable inside that class. You have to call echo $fn->ehe() in order to access a method. Methods and functions always have to be called with their parentheses, even if they don't receive parameters (well, not "always"... there are exceptions like echo, to mention one). Commented Sep 21, 2013 at 21:46

2 Answers 2

1

You need to call it, it's a function, not a property.

echo $fn->ehe();
Sign up to request clarification or add additional context in comments.

1 Comment

I did it, I have imminent problem again Notice: Undefined variable: table in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\... on line 178
0

There are several problems with your code:

  • You're accessing ehe as if it were a property rather than a method. Method calls always have (), which contain arguments if necessary.
  • You can't modify the visibility of variables in the global scope - your public $table; will cause a syntax error.
  • $table is out of scope in your ehe() method.

You could potentially use the global keyword:

$table;

class Functions {
    public function ehe() {
        global $table;
        return $table[4];
    }
}

$fn = new Functions();

/* static tables */
$table = array(
            0 => 'account.account',
            1 => 'player.player',
            2 => 'auction_house.items',
            3 => 'auction_house.admin',
            4 => 'auction_house.store',
            5 => 'auction_house.styles',
            6 => 'auction_house.logs',
            7 => 'auction_house.coupons',
        );

echo $fn->ehe(); // auction_house.store

3 Comments

Yes that's it. But I am using this table variables from system.php, system.php is a static file for another functions (without classes.) So here, I am trying to use this variables for both. Function class & other functions.. I hope you understand me.
@AlihanPehlivan look at the return language constructor documentation. It says that you could use return in a script used by include() to actually return something to another script. I was wondering if you could include something inside your class ;)
still system.php & another classes connected(included) I had another problem but now solved @AlejandroIván also I was using global keyword for my old functions, I did not know working for classes :)

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.