By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
15 Replies


P: n/a
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

P: n/a
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

P: n/a
..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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
..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

P: n/a
..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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
..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 discussion thread is closed

Replies have been disabled for this discussion.