[PHP]
<?php
//clsrecordset.ph p
class Recordset extends Database{
public function Recordset( ) { }
public function query( ) { }
public function endOfFile ( ) { }
}
?>[/PHP]
[PHP]<?php
//clssearchindex. php
require_once('c lsrecordset.php ');
class Searchindex {
private c_rs;
public function Searchindex ( ) {
$this->c_rs = new Recordset( );
}
public function getSQL ( ) { }
public function getData ( ) {
$rs = $this->c_rs->query($this->getSQL()); // error occurred this line
$this->c_rs->query($this->getSQL());
if ( $this->c_rs->endOfFile() ) {
$norecs = true;
}
}
}
?>[/PHP]
Error message: Call to a member function query() on a non-object
Additional, when I type the $this->c_rs-> , there is no intellisense on this case that's why I know there is something wrong and couldn't find the function.
Help: How can I call the function from the initiated class in order to use in other class?
11 2158 Atli 5,058
Recognized Expert Expert
Are you sure you have called the method that initializes the c_rs object?
You should consider adding a constructor to initialize it, then there will be no risk of the variable not being initialized.
Are you sure you have called the method that initializes the c_rs object?
You should consider adding a constructor to initialize it, then there will be no risk of the variable not being initialized.
[PHP]<?php
$pg = new Searchindex ( );
$pg->getData ( );
?>[/PHP]
Yes Sir, I use the new operator during initiation of the class then it is automatically invoke the Searchindex con structor.
Atli 5,058
Recognized Expert Expert
[PHP]<?php
$pg = new Searchindex ( );
$pg->getData ( );
?>[/PHP]
Yes Sir, I use the new operator during initiation of the class then it is automatically invoke the Searchindex con structor.
Yea sorry, totally overlooked that. I've gotten to used to the __construct() syntax :)
The error is where you create the c_rs variable, you forgot the $ before the variable name.
Yea sorry, totally overlooked that. I've gotten to used to the __construct() syntax :)
The error is where you create the c_rs variable, you forgot the $ before the variable name.
I think it is documented in php documentation when accessing the members itself, you only need the member name before $this-> .
For example:
[PHP]<?php
class MyClass {
private var1;
public var2;
public function MyClass ( ) {
// variable members initialization
$this->var1 = 1;
$this->var2 = "variable2" ;
// also calling function members
$this->MyFunction ( );
// "$" should be use when you need local variable.
// Therefore, $this->var? and $var? are treated differently.
$var1 = 2;
$var2 = "variable2" ;
$result = $this->var1 + $var1; // output 3
}
public function MyFunction ( ) { }
}
?>[/PHP]
The above are the basics of PHP OOP, therefore it is not questionable unless I overlooked the code after my several times of investigations of what is really happening.
I created this topic because I feel strange of the error.. It must be correct syntactically and logically....
I am very sorry guys I just missed looked / overlooked the code.
The code posted here was different in my source code.
[PHP]<?php
class Searchindex ( ) {
private $c_rs;
public function Searchindex ( ) {
/* this is the problem.
* It should be $this->c_rs = new Recordset ( );
*/
$c_rs = new Recordset ( );
}
}
?>[/PHP]
I make my own headache ;).. Thanks guys. TOPIC CLOSED Atli 5,058
Recognized Expert Expert
Glad your code is working now.
Just to clear things up tho, take a look at this: -
class myclass
-
{
-
// This is incorrect, and will cause errors!
-
private myVar;
-
-
// This is correct
-
private $myvar;
-
-
function testFunc() {
-
// This is correct, and will always refer to the variable
-
// we declared before the function.
-
echo $this->myvar;
-
-
# EDIT, got this wrong the first time. It has been corrected.
-
// This is not valid, it appears that the class variable
-
// $myvar does not exist inside the scope of this function.
-
// This will cause PHP to print a warning, if warnings are enabled.
-
echo $myvar;
-
}
-
}
-
Glad your code is working now.
Just to clear things up tho, take a look at this: -
class myclass
-
{
-
// This is incorrect, and will cause errors!
-
private myVar;
-
-
// This is correct
-
private $myvar;
-
-
function testFunc() {
-
// This is correct, and will always refer to the variable
-
// we declared before the function.
-
echo $this->myvar;
-
-
// This is also correct, because the myvar variable
-
// is declared inside the class, but any instances of
-
// of $myvar inside the function will take over the scope.
-
echo $myvar;
-
}
-
}
-
Do you mean $this->myvar and $myvar are the same memory location? It means changes in $myvar are automatically reflected in $this->myvar and viceversa?
Atli 5,058
Recognized Expert Expert
Do you mean $this->myvar and $myvar are the same memory location? It means changes in $myvar are automatically reflected in $this->myvar and viceversa?
No, it doesn't appear to work like that. I thought it did tho :/
Which means my earlier post was wrong. (I've edited it btw to show the error)
I made a simple test: -
class myclass
-
{
-
private $myvar;
-
-
function myfunc()
-
{
-
$this->myvar = 5;
-
-
echo $myvar; // = 'Undefined wariable' warning.
-
echo $this->myvar; // = 5
-
-
$myvar = 10;
-
-
echo $myvar; // = 10
-
echo $this->myvar; // = 5
-
}
-
}
-
So based on that, class variables can not be used inside class methods without $this.
It is possible, however, that this behavior may vary based on your configuration. This test was done using the default configuration.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {
document.images.src = eval("mt" +menu+ ".src")
}
alert("imgOff_hidemenu");
hideMenu=setTimeout('Hide(menu,num)',500);
|
by: Harshankumar |
last post by:
Hello,
I have the following questions
1) can we pass the parameters to interrupt?
2)can we return the parameters from interrupt
Regards
harshan
|
by: Bill Borg |
last post by:
Hello,
I call a function recursively to find an item that exists *anywhere* down
the chain. Let's say I find it five layers deep. Now I've got what I need and
want to break out of that whole stack and continue execution at the point of
the initial call. Is that possible?
Thanks,
Bill
|
by: Pawan Narula via DotNetMonster.com |
last post by:
hi all,
i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly.
now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
|
by: Lore Leunoeg |
last post by:
If I call a delegates BeginInvoke a new thread from the threadpool is
started. But what happens if I call the Invoke method? Does this also start
a new thread?
Thank you
sincerely
Lore
| |
by: Terry Olsen |
last post by:
I'm running an asynchronous Socket. In the ReceiveCallback method, I need
to append what is received to a textbox on the main form. I have this code:
Private Sub ToChatWindow(ByVal msg As String)
txtChat.AppendText(msg)
End Sub
I've never used a delegate or invoke before and I'm rather confused on the
topic. Hope someone can help.
|
by: cindy |
last post by:
I have a form, has javascript registered so a modal pops up.
Button click will close form.
Now I need to do an update with modal form data before it closes.
I can put a second button and register the onclick attribute of the second
button
to the javascript to close the form after user clicks upload button
click upload do the update to database then programmatically click the
second button the use on onclick attribute that sees the...
|
by: Dom |
last post by:
I'm teaching myself about delegates and the Invoke method, and I have
a few newbie questions for the gurus out there:
Here are some CSharp statements:
1. public delegate void MyDelegate (int k, string s)
2. MyDelegate MyDelegateVar = MyMethod
3. MyForm.Invoke (MyDelegateVar)
Some questions:
|
by: balabaster |
last post by:
I have a class that I want to make thread-safe and am investigating the ISyncronizeInvoke interface and wondering just what it will take to implement this interface. So far the basic concept of my code is:
Public Class MyClass1
Implements System.ComponentModel.ISynchronizeInvoke
Private _InvokeRequired As Boolean = False
Public Function BeginInvoke(ByVal method As System.Delegate, ByVal args() As Object) As...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |