简体   繁体   中英

php return object of class from a function

I'm using this class to create php FORM

http://smarttechdo.com/~avb/pfbc/api/

and I need to use this class through function, something like this

function getLogin() {
  Form::open ("login");
    echo "<legend>Login</legend>";
    Form::Hidden ("id");
    Form::Email ("Email Address:", "email", array("required" => 1));
    Form::Password ("Password:", "password", array("required" => 1));
    Form::Checkbox ("", "remember", array("1" => "Remember me"));
    Form::Button ("Login");
    Form::Button ("Cancel", "button", array("onclick" => "history.go(-1);"));
  Form::close (false);

  return ???
}

How to do that ?

EDIT : I need to return as json data

$var = getLogin();
echo json_encode($var);

It seems Form is static so you don't need return any value. You can use in other place just in the same way as in this function.

Like said mitch, Form only uses static methods, you have two choices :

  1. Don't return anything
  2. Try to find a static method inside Form class, that return your current instance. Maybe a Form::get('Login') ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM