473,796 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does my class require the public accessor for my member?

Consider:
<?php

echo "start";

class myClass
{

public $connection;

function getme()
{
$this->connection = "test";
return $this->connection;

}

}

$database = new myClass();
$mytest = $database->getme();
echo $mytest;
echo "done";

?>

If I remove the "public $connection" above and have it just as
"$connectio n," I get nothing. Nothing loads, not start, done,
nothing, no html tags, no errors, nada. Make me thinks it's an error,
but when I use error_reporting , I get nothing also. If I put the
public modifier back in I get the results. I thought I could make
$connection private and access it from my accessor, getme().

What am I doing wrong? And, why doesn't php complain if I did my
class wrong? Thank you.
Sep 15 '08
15 1563
..oO(Jerry Stuckle)
>Micha, he gets a syntax error but doesn't have display_errors enabled.
I just didn't understand what he meant with

| If I remove the "public $connection" above and have it just as
| "$connectio n," I get nothing.

But I got it now.

Micha
Sep 16 '08 #11
..oO(Jerry Stuckle)
>First of all, display_errors= "stdout" is invalid. It is either
display_errors =on or display_errors= off
As of PHP 5.2.4 this directive is of type string and allows the values
"stderr" and "stdout". Before it was a boolean.

I didn't knew that either ...

Micha
Sep 16 '08 #12
On Sep 16, 12:45*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
jmDesktop wrote:
On Sep 16, 11:47 am, Curtis <dye...@gmail.c omwrote:
jmDesktop wrote:
Consider:
<?php
echo "start";
class myClass
{
* *public $connection;
* *function getme()
* *{
* * *$this->connection = "test";
* * *return $this->connection;
* *}
}
$database = new myClass();
$mytest = $database->getme();
echo $mytest;
echo "done";
?>
If I remove the "public $connection" above and have it just as
"$connection ," I get nothing. *Nothing loads, not start, done,
nothing, no html tags, no errors, nada. *Make me thinks it's an error,
but when I use error_reporting , I get nothing also. *If I put the
public modifier back in I get the results. *I thought I could make
$connection private and access it from my accessor, getme().
What am I doing wrong? *And, why doesn't php complain if I did my
class wrong? *Thank you.
As Jerry has explained, it's not "display_er rors on", it's
display_errors = On
Also, if you want to make class members private, use the "private"
keyword. Within a class definition, you have to precede property
declarations with a visibility keyword, or "var", which is equivalent
to "public", and exists for compatibility with PHP4. All of this info
is readily available in the PHP docs:
<URL:http://php.net/manual/en/language.oop5.v isibility.php>
Example:
class Foo {
* * private $bar;
* * function getBar() {
* * * *return $this->bar;
* * }
}
--
Curtis- Hide quoted text -
- Show quoted text -
Thanks. I left out the equals, but I have changed it to this:
; To output errors to STDERR with CGI/CLI:
;display_errors = "stderr"
;
; Default
;
display_errors = "stdout"
and have tried
display_errors = On
(no quotes)
but I never get the errors. *Don't know why. *I have restarted the
httpd server after making the change. *Maybe IIS doesn't like it.
It's probably me.

First of all, display_errors= "stdout" is invalid. *It is either
display_errors= on or display_errors= off

Second of all, ensure you're changing the correct php.ini. *phpinfo()
will show you which php.ini you're actually using, and the status of
display_errors.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===- Hide quoted text -

- Show quoted text -
You were correct. I was not using right php.ini. Sorry for bothering
everyone. Thank you for your help.
Sep 16 '08 #13
Michael Fesser wrote:
.oO(Jerry Stuckle)
>First of all, display_errors= "stdout" is invalid. It is either
display_errors =on or display_errors= off

As of PHP 5.2.4 this directive is of type string and allows the values
"stderr" and "stdout". Before it was a boolean.

I didn't knew that either ...

Micha
Interesting. Not much of a note in the doc, is there?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #14
jmDesktop wrote:
On Sep 16, 12:45 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>jmDesktop wrote:
>>On Sep 16, 11:47 am, Curtis <dye...@gmail.c omwrote:
jmDesktop wrote:
Consider:
<?php
echo "start";
class myClass
{
public $connection;
function getme()
{
$this->connection = "test";
return $this->connection;
}
}
$database = new myClass();
$mytest = $database->getme();
echo $mytest;
echo "done";
?>
If I remove the "public $connection" above and have it just as
"$connectio n," I get nothing. Nothing loads, not start, done,
nothing, no html tags, no errors, nada. Make me thinks it's an error,
but when I use error_reporting , I get nothing also. If I put the
public modifier back in I get the results. I thought I could make
$connecti on private and access it from my accessor, getme().
What am I doing wrong? And, why doesn't php complain if I did my
class wrong? Thank you.
As Jerry has explained, it's not "display_er rors on", it's
display_erro rs = On
Also, if you want to make class members private, use the "private"
keyword. Within a class definition, you have to precede property
declaratio ns with a visibility keyword, or "var", which is equivalent
to "public", and exists for compatibility with PHP4. All of this info
is readily available in the PHP docs:
<URL:http://php.net/manual/en/language.oop5.v isibility.php>
Example:
class Foo {
private $bar;
function getBar() {
return $this->bar;
}
}
--
Curtis- Hide quoted text -
- Show quoted text -
Thanks. I left out the equals, but I have changed it to this:
; To output errors to STDERR with CGI/CLI:
;display_erro rs = "stderr"
;
; Default
;
display_error s = "stdout"
and have tried
display_error s = On
(no quotes)
but I never get the errors. Don't know why. I have restarted the
httpd server after making the change. Maybe IIS doesn't like it.
It's probably me.
First of all, display_errors= "stdout" is invalid. It is either
display_errors =on or display_errors= off

Second of all, ensure you're changing the correct php.ini. phpinfo()
will show you which php.ini you're actually using, and the status of
display_errors .

--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attg lobal.net
============== ====- Hide quoted text -

- Show quoted text -

You were correct. I was not using right php.ini. Sorry for bothering
everyone. Thank you for your help.
No trouble - it's a common problem in this newsgroup :-)

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #15
..oO(Jerry Stuckle)
>Michael Fesser wrote:
>.oO(Jerry Stuckle)
>>First of all, display_errors= "stdout" is invalid. It is either
display_error s=on or display_errors= off

As of PHP 5.2.4 this directive is of type string and allows the values
"stderr" and "stdout". Before it was a boolean.

I didn't knew that either ...

Micha

Interesting. Not much of a note in the doc, is there?
http://www.php.net/manual/en/errorfu...display-errors

Micha
Sep 17 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2067
by: Todd A. Anderson | last post by:
I've inherited two "C++" code bases that I have to tie together and both of them make frequest use of public member variables in spite of all the information saying this limits flexibility. Well, their lack of foresight has bit me of course! I'd like to start off by converting all their public member variable accesses to the use of accessor methods. Then, I can reimplement selected accessor methods to provide the necessary glue between...
6
2179
by: Chris Mantoulidis | last post by:
Forgive me if I'm wrong but I think there is something like an extra member scope in classes. for example: class abc { ostream & operator << (ostream &, const abc &); istream & operator >> (istream &, abc &); private:
18
1433
by: Jason Heyes | last post by:
Is this class evidence of poor design? class Rectangle { double width, height; public: double get_width() const { return width; } double get_height() const { return height; } void set_width(double width) { this->width = width; }
1
1850
by: Matthias Kaeppler | last post by:
Sorry if this has been discussed before (I'm almost certain it has), but I didn't know what to google for. My problem is, I have a class, a gtkmm widget, and I want it to serve as a base class now, but I'm not sure if I'm taking the proper steps in order to not break the whole class. Are there any guidelines what I have to watch out for? One question would e.g. be:
11
5723
by: Shea Martin | last post by:
I have been programming in C++ for over 4 years. I *think* I knew that a struct could have a constructor but I decided to dig into it a little more today, and found that there is very little difference between a struct and a class in C++. Both have inheritance, access modifiers, etc. The only diff I see is the default access level is public vs. private. I have always just used structs as a minimal class, as that is the way
12
1988
by: Viru Rathore | last post by:
If struct keyword is support the all functionallity of class keyword, only differance i have found is accessibility of member is different in struct is public and class has private. This accessbility feature user can got by using Accessor public, private or protected. So why class keyword is implemented in C++.
23
2099
by: grubertm | last post by:
When accessing pointer member variables these are not treated as const even though the instance is const. This came as a complete surprise to me and I would appreciate some feedback why that is the case. Here's a snippet: class MyClass { public: char *pChar; }; void ChangePointedTo (char *ch)
10
2101
by: Pavel Shved | last post by:
Is there a program of wide use that automatically extracts template parameters requirements from source code of template functions? I mean the following: assume we have a template function that demands its template parameter(s) to meet certain requirements. For example simple sorting function template <typename Tvoid sort(T* t, int N) { for (int i=0;i<N-1; i++)
20
1484
by: d.s. | last post by:
I've got an app with two classes, and one class (InventoryInfoClass) is an object within the other class (InventoryItem). I'm running into problems with trying to access (get/set) a private variable within the included class (InventoryInfo) from the "including" class (InventoryItem). Here's the code, trimmed down. I've included ********* at the start of the first line that's blowing up on me. I'm sure others that try to access the...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10455
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...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
tracyyun
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...
1
7547
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
5441
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...
1
4116
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
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
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.