473,785 Members | 2,602 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 #1
15 1561
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
$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.
You don't see any errors because error_reporting and/or display_errors
is disabled.

In your php.ini file, ensure you have:

display_errors= on
error_reporting =E_ALL

Enable these and you'll see your syntax error.

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

Sep 15 '08 #2
On Sep 15, 7:53*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
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
$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.

You don't see any errors because error_reporting and/or display_errors
is disabled.

In your php.ini file, ensure you have:

display_errors= on
error_reporting =E_ALL

Enable these and you'll see your syntax error.

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

- Show quoted text -
I tried that with:

error_reporting = E_ALL

; Print out errors (as a part of the output). For production web
sites,
; you're strongly encouraged to turn this feature off, and use error
logging
; instead (see below). Keeping display_errors enabled on a production
web site
; may reveal security information to end users, such as file paths on
your Web
; server, your database schema or other information.
;
; possible values for display_errors:
;
; Off - Do not display any errors
; stderr - Display errors to STDERR (affects only CGI/CLI
binaries!)
; On or stdout - Display errors to STDOUT (default)
;
; To output errors to STDERR with CGI/CLI:
;display_errors = "stderr"
;
; Default
;
display_errors On

; Even when display_errors is on, errors that occur during PHP's
startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup _errors off, except for when debugging.
display_startup _errors = On

I just get a blank page. I put the public modifier in it works.
Sep 16 '08 #3
..oO(jmDesktop)
>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.
Not sure what you mean. Can you post the code that does not work?

Micha
Sep 16 '08 #4
On Sep 16, 10:02*am, Michael Fesser <neti...@gmx.de wrote:
.oO(jmDesktop)


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.

Not sure what you mean. Can you post the code that does not work?

Micha- Hide quoted text -

- Show quoted text -
It is in the original post. I got it to work by using a modifier or
public or private, but now I don't know why error reporting isn't
working.
Sep 16 '08 #5
jmDesktop wrote:
On Sep 15, 7:53 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>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.
You don't see any errors because error_reporting and/or display_errors
is disabled.

In your php.ini file, ensure you have:

display_errors =on
error_reportin g=E_ALL

Enable these and you'll see your syntax error.

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

- Show quoted text -

I tried that with:

error_reporting = E_ALL

; Print out errors (as a part of the output). For production web
sites,
; you're strongly encouraged to turn this feature off, and use error
logging
; instead (see below). Keeping display_errors enabled on a production
web site
; may reveal security information to end users, such as file paths on
your Web
; server, your database schema or other information.
;
; possible values for display_errors:
;
; Off - Do not display any errors
; stderr - Display errors to STDERR (affects only CGI/CLI
binaries!)
; On or stdout - Display errors to STDOUT (default)
;
; To output errors to STDERR with CGI/CLI:
;display_errors = "stderr"
;
; Default
;
display_errors On

; Even when display_errors is on, errors that occur during PHP's
startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup _errors off, except for when debugging.
display_startup _errors = On

I just get a blank page. I put the public modifier in it works.
Please see my comment above. It is

display_errors= On

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

Sep 16 '08 #6
Michael Fesser wrote:
.oO(jmDesktop)
>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.

Not sure what you mean. Can you post the code that does not work?

Micha
Micha, he gets a syntax error but doesn't have display_errors enabled.

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

Sep 16 '08 #7
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
$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
Sep 16 '08 #8
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
$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.
Sep 16 '08 #9
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_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
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.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #10

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

Similar topics

2
2066
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
2178
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
5722
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
2098
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
1483
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
9645
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
10336
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
10095
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
9953
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...
0
8978
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
7502
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.