Calling functions from within each other not working

这里的代码!不工作,请帮助。

class user{
var idgen;

function uid(){
    //return uniqid (rand(), true);
    return "123";
    }

function gen() {
    $this->idgen=$this->uid();
            //$this->idgen=udi();//even this dint work
    }

function pint() {
    echo "The id is :".$this->idgen;
    }
}

$use= new user();
$use->gen();
$use->pint();

Change the second line of your code to

private $idgen;

and voila! :)

BTW it's worth setting error reporting on; it really helps debugging.

You can do it by editing the php.ini file or adding this somewhere in your project:

ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'On'); // <-- change this to off when live.

Put this in a file with other settings and include it in every page.


public $idgen; instead of var idgen;


Change:

var idgen;

With:

public $idgen = '';
链接地址: http://www.djcxy.com/p/96578.html

上一篇: 在IntelliJ IDEA下使用Lombok时无法编译项目

下一篇: 从对方内部调用功能不起作用