Answers.Body: <p>You need to backslash the class to tell it to look in the global namespace like so:</p>
  
  <pre><code>public function validateVatNumber()
  {
      $client = new \SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
  }
  </code></pre>
  
  <p>You can read on the basics of PHP namespacing here: <a href="http://php.net/manual/en/language.namespaces.basics.php" rel="nofollow">http://php.net/manual/en/language.namespaces.basics.php</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-28T14:57:10.870Z
Answers.LastActivityDate: 2014-10-28T14:57:10.870Z
Answers.UserDisplayName: Brad Bell
Body: <p>I need to make a SoapClient <code>new SoapClient</code> call from within one of my Models for a validation rule. When I create the new SoapClient instance class in my Model function I'm getting this error message:</p>
  
  <pre><code>Fatal error: Class 'Craft\SoapClient' not found in...
  </code></pre>
  
  <p>I get the same error message whatever file Model/Service/Controller i put it in.</p>
  
  <pre><code>public function validateVatNumber()
  {
      $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
  }
  </code></pre>
  
  <p>Could anyone let me know what I should do to be able to make these calls? I'm guessing I somehow need to "break free" from the <em>Craft</em> namespace.</p>
  
  <p>Thank you</p>
  
Tags: <plugin-development>
Title: How call PHP native function in Model/Service/Controller scope
ThreadText: # How call PHP native function in Model/Service/Controller scope
  
  (Asked by: username_0 on 2014-10-28)
  
  I need to make a SoapClient `new SoapClient` call from within one of my Models for a validation rule. When I create the new SoapClient instance class in my Model function I'm getting this error message:
  
  ```
  Fatal error: Class 'Craft\SoapClient' not found in...
  
  ```
  
  I get the same error message whatever file Model/Service/Controller i put it in.
  
  ```
  public function validateVatNumber()
  {
      $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
  }
  
  ```
  
  Could anyone let me know what I should do to be able to make these calls? I'm guessing I somehow need to "break free" from the *Craft* namespace.
  
  Thank you
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-10-28. Score: 2 | Accepted answer
  
  You need to backslash the class to tell it to look in the global namespace like so:
  
  ```
  public function validateVatNumber()
  {
      $client = new \SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
  }
  
  ```
  
  You can read on the basics of PHP namespacing here: <http://php.net/manual/en/language.namespaces.basics.php>
  
  
  ---
  
  