You should read a bit about scopes in PHP. Your variable client is not set in your function because that is another scope. There are some solutions to handle that. You can get the variable with global but that is not really cool.
function getFirstName($code){
global $client;
$firstname = $client->getFirstName(array('code' => $code));
return $firstname->return;
}
You shouldn't do that. When you work with globals you don't know where your variable come from.
Another solution is to define your variable as function parameter.
function getFirstName($code, $client) {
thats much better. If you work with classes you can define the variable as class variable thats much better. For example:
class ApiConnection {
private $serviceWsdl = 'http://localhost:8080/Test/services/Test?wsdl';
private $client;
public function __construct() {
$this->client = new SoapClient($this->serviceWsdl);
}
public function getFirstName($code){
$firstname = $this->client->getFirstName(array('code' => $code));
return $firstname->return;
}
}
i haven't tested that code but its much better to work with classes.