I'm working through the O'Reilly book "PHP, MySQLm and JavaScript" by
Robin Nixon and the following example is in the book.
<?php
Translate::lookup();
class Translate
{
const ENGLISH = 0;
const SPANISH = 1;
const FRENCH = 2;
const GERMAN = 3;
// ...
function lookup()
{
echo self::SPANISH;
}
}
?>
Now I'm supposed to get s simple "1" as output. Instead I get some
warning about "Strict standards" (screenprint: http://i53.tinypic.com/28jkswl.jpg).
Is it some new PHP thingie or is is something I can turn off in my
PHP.ini or what?
I looked through the php.net documentation, but I can't find anything
that easily matches what I'm seeing. So I'd also appreciate if y'all
could tell me how to figure out these kind of errors.
Thanks much.
|
|
0
|
|
|
|
Reply
|
MikeB
|
8/31/2010 7:20:22 PM |
|
On 08/31/2010 03:20 PM, MikeB wrote:
> Now I'm supposed to get s simple "1" as output. Instead I get some
> warning about "Strict standards" (screenprint: http://i53.tinypic.com/28jkswl.jpg).
>
> Is it some new PHP thingie or is is something I can turn off in my
> PHP.ini or what?
>
> I looked through the php.net documentation, but I can't find anything
> that easily matches what I'm seeing. So I'd also appreciate if y'all
> could tell me how to figure out these kind of errors.
>
> Thanks much.
That message is OK. You are calling a non-static method in a static context.
You will fix that simply, just replace
function lookup()
with
static function lookup()
If you want to manage how error messages are shown.
http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
And
http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
|
|
0
|
|
|
|
Reply
|
marious.barrier (161)
|
8/31/2010 7:37:30 PM
|
|
..oO(MikeB)
>I'm working through the O'Reilly book "PHP, MySQLm and JavaScript" by
>Robin Nixon and the following example is in the book.
>
><?php
>Translate::lookup();
>
>class Translate
>{
> const ENGLISH = 0;
> const SPANISH = 1;
> const FRENCH = 2;
> const GERMAN = 3;
> // ...
>
> function lookup()
> {
> echo self::SPANISH;
> }
>}
>?>
>
>
>Now I'm supposed to get s simple "1" as output. Instead I get some
>warning about "Strict standards" (screenprint: http://i53.tinypic.com/28jkswl.jpg).
>
>Is it some new PHP thingie or is is something I can turn off in my
>PHP.ini or what?
It's a sloppiness in your code. The warning pretty much explains it:
You're calling the lookup() method statically, even though it's not
declared as static. There are two possible solutions:
1) Create an instance first, then call the lookup() method:
$foo = new Translate();
$foo->lookup();
2) Declare the method as static:
class Translate {
...
public static function lookup() {
echo self::SPANISH;
}
}
>I looked through the php.net documentation, but I can't find anything
>that easily matches what I'm seeing.
http://www.php.net/manual/en/language.oop5.static.php
| Calling non-static methods statically generates an E_STRICT level
| warning.
Micha
|
|
0
|
|
|
|
Reply
|
netizen9200 (1825)
|
8/31/2010 7:39:40 PM
|
|
On 8/31/2010 3:20 PM, MikeB wrote:
> I'm working through the O'Reilly book "PHP, MySQLm and JavaScript" by
> Robin Nixon and the following example is in the book.
>
> <?php
> Translate::lookup();
>
> class Translate
> {
> const ENGLISH = 0;
> const SPANISH = 1;
> const FRENCH = 2;
> const GERMAN = 3;
> // ...
>
> function lookup()
> {
> echo self::SPANISH;
> }
> }
> ?>
>
>
> Now I'm supposed to get s simple "1" as output. Instead I get some
> warning about "Strict standards" (screenprint: http://i53.tinypic.com/28jkswl.jpg).
>
> Is it some new PHP thingie or is is something I can turn off in my
> PHP.ini or what?
>
> I looked through the php.net documentation, but I can't find anything
> that easily matches what I'm seeing. So I'd also appreciate if y'all
> could tell me how to figure out these kind of errors.
>
> Thanks much.
>
>
>
You're trying to call a non-static function without having an object of
the class. Check the errata for the book - I'm seeing mixed reviews on
O'Reilly's web site because of the number of errors in the book.
BTW, rather than put up screen shots, please just the results here -
especially if it's a short message like this. It is much easier to
follow the thread when everything is in one place.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
0
|
|
|
|
Reply
|
jstucklex (14410)
|
8/31/2010 7:40:06 PM
|
|
On Aug 31, 2:40=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 8/31/2010 3:20 PM, MikeB wrote:
>
>
>
> > I'm working through the O'Reilly book "PHP, MySQLm and JavaScript" by
> > Robin Nixon and the following example is in the book.
>
> > <?php
> > Translate::lookup();
>
> > class Translate
> > {
> > =A0 =A0const ENGLISH =3D 0;
> > =A0 =A0const SPANISH =3D 1;
> > =A0 =A0const FRENCH =A0=3D 2;
> > =A0 =A0const GERMAN =A0=3D 3;
> > =A0 =A0// ...
>
> > =A0 =A0function lookup()
> > =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0echo self::SPANISH;
> > =A0 =A0}
> > }
> > ?>
>
> > Now I'm supposed to get s simple "1" as output. Instead I get some
> > warning about "Strict standards" (screenprint:http://i53.tinypic.com/28=
jkswl.jpg).
>
> > Is it some new PHP thingie or is is something I can turn off in my
> > PHP.ini or what?
>
> > I looked through the php.net documentation, but I can't find anything
> > that easily matches what I'm seeing. So I'd also appreciate if y'all
> > could tell me how to figure out these kind of errors.
>
> > Thanks much.
>
> You're trying to call a non-static function without having an object of
> the class. =A0Check the errata for the book - I'm seeing mixed reviews on
> O'Reilly's web site because of the number of errors in the book.
Yes, I did this at http://oreilly.com/catalog/errata.csp?isbn=3D97805961571=
42,
but that particular error does not seem to be flagged. I'm suspecting
that since it does work, it has to do with the E_STRICT error option
that seems to have been introduced in PHP5. Perhaps the author did not
have it turned on.
Now all that is left for me is to figure out the advice I've been
given here about correcting the code - I can't say that I can wrap my
head around the static issues very well right now.
>
> BTW, rather than put up screen shots, please just the results here -
> especially if it's a short message like this. =A0It is much easier to
> follow the thread when everything is in one place.
>
Yes, sorry about that. It was so colorful, I thought some information
might have been in the way it was displayed, since I'm not used to
programming languages being so elaborate when displaying error
messages.
|
|
0
|
|
|
|
Reply
|
MPBrede (98)
|
8/31/2010 11:01:26 PM
|
|
On Aug 31, 2:37=A0pm, Marious Barrier <marious.barr...@gmail.com> wrote:
> On 08/31/2010 03:20 PM, MikeB wrote:
>
> > Now I'm supposed to get s simple "1" as output. Instead I get some
> > warning about "Strict standards" (screenprint:http://i53.tinypic.com/28=
jkswl.jpg).
>
> > Is it some new PHP thingie or is is something I can turn off in my
> > PHP.ini or what?
>
> > I looked through the php.net documentation, but I can't find anything
> > that easily matches what I'm seeing. So I'd also appreciate if y'all
> > could tell me how to figure out these kind of errors.
>
> > Thanks much.
>
> That message is OK. You are calling a non-static method in a static conte=
xt.
>
> You will fix that simply, just replace
>
> function lookup()
>
> with
>
> static function lookup()
>
> If you want to manage how error messages are shown.
>
> http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-...
>
> And
>
> http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-re...
Thanks much, this worked. And I'll submit this as an errata to the
book.
|
|
0
|
|
|
|
Reply
|
MPBrede (98)
|
9/1/2010 12:46:11 AM
|
|
..oO(MikeB)
>On Aug 31, 2:37�pm, Marious Barrier <marious.barr...@gmail.com> wrote:
>>
>> If you want to manage how error messages are shown.
>>
>> http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-...
>>
>> And
>>
>> http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-re...
>
>Thanks much, this worked. And I'll submit this as an errata to the
>book.
On a development machine error reporting should be set as high as
possible. E_ALL is a must, E_ALL|E_STRICT would be preferred. _All_
messages, even E_NOTICE errors, should be taken care of.
Micha
|
|
0
|
|
|
|
Reply
|
netizen9200 (1825)
|
9/1/2010 6:35:30 PM
|
|
On Sep 1, 2:35=A0pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(MikeB)
>
> >On Aug 31, 2:37=A0pm, Marious Barrier <marious.barr...@gmail.com> wrote:
>
> >> If you want to manage how error messages are shown.
>
> >>http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-..=
..
>
> >> And
>
> >>http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-re..=
..
>
> >Thanks much, this worked. And I'll submit this as an errata to the
> >book.
>
> On a development machine error reporting should be set as high as
> possible. E_ALL is a must, E_ALL|E_STRICT would be preferred. _All_
> messages, even E_NOTICE errors, should be taken care of.
IMHO, passing (E_ALL | E_STRICT) is mandatory when you're writing a
book on PHP!
|
|
0
|
|
|
|
Reply
|
matthew.leonhardt (133)
|
9/1/2010 7:55:35 PM
|
|
|
7 Replies
889 Views
(page loaded in 0.087 seconds)
|