Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3456256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:42:51+00:00 2026-05-18T09:42:51+00:00

Hey everyone, I am trying to consume a WebService using PHP SoapClient . Now,

  • 0

Hey everyone, I am trying to consume a WebService using PHP SoapClient.
Now, everything is working fine until I try to use a ComplexType variable.
I am getting a NullPointerException from the web service.

Here is an example ComplexType variable’s class:

class A {
public $var1 = 0; //int
public $var2; //Object: B
}

Now, I am making an object like this:

$a = new A();
$a->var2 = new B();

But, this has to be done every time I make an object of A.
Is there a method to initialize $var2 in class A, without using the constructors for it, like we are doing for $var1?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:42:51+00:00Added an answer on May 18, 2026 at 9:42 am

    Yes, is possible if using PHP overloading

    class A
    {
      public $var1 = 0;
      /* note $var2 cannot declare here */
    
      public function __get($name)
      {
        switch ($name)
        {
          case 'var2':
            return new B();
            break;
        }
      }
    }
    
    class B
    {
      public $var3 = 1;
      public function __construct()
      {
        $this->name = 'this is class b';
      }
    }
    
    $a = new A();
    var_dump( $a->var2 );
    var_dump( $a->var2->var3 );
    var_dump( $a->var2->name );
    

    Is called using $a->var2 instead of $a->$var2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
Hey everyone, I am trying to run the following program, but am getting a
Hey everyone. I'm trying to make a swing GUI with a button and a
Hey everyone. I am trying to incorporate a simple UINavigationController into my tab bar
Hey everyone, I am trying to hide/show different html elements (div, etc...) based on
Hey everyone, today I'm trying to get a link to an XML file passed
Hey everyone, my first time trying to draw a multi-color gradient in actionscript 3.
Hey everyone, I am trying to figure out a way to query my mysql
Hey everyone, my problem is that im trying to figure out how to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.