473,800 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regarding object reference

4 New Member
Hello to members,

I am getting fatal error while running the following code. Any solutions to avoid the error.
The error is
PHP Fatal error: Call to a member function getD() on a non-object in ..... on line 24.

The objective is to call the getValue() function of of D type object. Your guidance is required. I am using PHP5+ and Apache 2.2 on windows XP.

The code is below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. class Z{
  4.     function Z(){
  5.  
  6.     }
  7. }
  8. class A extends Z{
  9.     function A(){
  10.         parent::Z();
  11.     }
  12.  
  13.     function &getB(){
  14.         $b = new B();
  15.         return $b;
  16.     }
  17. }
  18.  
  19. class B{
  20.     private $c;
  21.     public function B(){
  22.         $this->c = new C();
  23.     }
  24.  
  25.     public function &getD(){
  26.         return $this->c->getD();
  27.     }
  28.  
  29.     public function &getE(){
  30.         return $this->c->getE();
  31.     }
  32. }
  33.  
  34. class C{
  35.     private $f;
  36.     public function C(){
  37.         $this->f = array();
  38.     }
  39.  
  40.     private function setD(){
  41.         $this->f[0][0] = new D();
  42.     }
  43.  
  44.     private function setE(){
  45.         $this->f[0][1] = new E();
  46.     }
  47.  
  48.     public function &getD(){
  49.         return $this->f[0][0];
  50.     }
  51.  
  52.     public function &getE(){
  53.         return $this->f[0][1];
  54.     }
  55. }
  56.  
  57. class D{
  58.  
  59.     public function D(){
  60.     }
  61.  
  62.     public function getValue(){
  63.         return "Val";
  64.     }
  65. }
  66.  
  67. class E{
  68.     public function E(){
  69.     }
  70.  
  71.     public function getValue(){
  72.         return "Eval";
  73.     }
  74.  
  75. }
  76.  
  77. $a = new A();
  78. $b =& $a->getB();
  79. $d = $b->getD();
  80. echo $d->getValue()
  81. ?>
  82.  
regards,
Nov 1 '07 #1
3 1210
amitabhcy
4 New Member
Hello again

The code provided is a simulation of a project I am working on. The object structure is the same as in the case of the project.

Kindly look into the code and inform how to correct.

regards,
Nov 1 '07 #2
code green
1,726 Recognized Expert Top Contributor
This is very complex.
Is the error occuring in this class?
[PHP]class B{
private $c;
public function B(){
$this->c = new C();
}

public function &getD(){
return $this->c->getD();
}

public function &getE(){
return $this->c->getE();
}
}[/PHP] I don't think the C class has had a D object instantiated, so this line is illegal [PHP]return $this->c->getD();[/PHP] Well it has but within an array[PHP]private function setD(){
$this->f[0][0] = new D();[/PHP] So C can reference an array of D objects but you have not specified which of them in the B class.
Well that is my guess. this really is complex.
Nov 1 '07 #3
amitabhcy
4 New Member
Is the error occuring in this class?
The error occurs in the line number 79 of the original post. The objects are getting created. This is verified with the print_r function.

It seems some where a reference should have been placed. Dunno where.

regards
Nov 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2112
by: Janus | last post by:
Hell This is a very basic question i know :O Formerly I developed in VisualBasic 6.0 and when a project is started you can select different project types. But what exactly is an ActiveX DLL? - Is it considered as a COM object I've heard something about its not a real dll because of the iUnknown, but what's that Im sorry for my lack of knowledge, but if someone could give me a quick primer I would be very happ
7
2210
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
2
1824
by: Renji Panicker | last post by:
I have a question regarding references. Consider the following code: <code> #include <iostream> class A { int _a1; int _a2; int _a3; };
16
2704
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why allocator write forward declaration then allocation for void* rather than directly wrote allocator first ?
5
2652
by: coolguyaroundyou | last post by:
Consider the following codes: class abc { int i; public: abc() : i(0) {} void func() { .....some code....} };
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.