473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
"$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.
Sep 15 '08 #1
15 1527
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_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*******@attglobal.net
==================

Sep 15 '08 #2
On Sep 15, 7:53*pm, Jerry Stuckle <jstuck...@attglobal.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_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...@attglobal.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.dewrote:
.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- 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...@attglobal.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_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...@attglobal.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*******@attglobal.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*******@attglobal.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
"$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_errors 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.visibility.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.comwrote:
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_errors 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.visibility.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.comwrote:
>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_errors 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.visibility.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*******@attglobal.net
==================

Sep 16 '08 #10
..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
| "$connection," 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...@attglobal.netwrote:
jmDesktop wrote:
On Sep 16, 11:47 am, Curtis <dye...@gmail.comwrote:
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_errors 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.visibility.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...@attglobal.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*******@attglobal.net
==================

Sep 16 '08 #14
jmDesktop wrote:
On Sep 16, 12:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 16, 11:47 am, Curtis <dye...@gmail.comwrote:
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_errors 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.visibility.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...@attglobal.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*******@attglobal.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_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?
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
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,...
6
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 >>...
18
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...
1
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...
11
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...
12
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...
23
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...
10
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...
20
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.