Changing INI settings has no effect

Hi fellas,

I just tried the following code with PHP 5.0.4 installed:

<?php
error_reporting(E_STRICT);
class myc {
    var $ttt;  // var is deprecated in PHP 5
    function test() {
    }
}
$x = new myc();
?>

but it does not show up the "deprecated" warning message in the browser as well as in the console (> php myfile.php).

But if I run this code in the console like:

> php -d error_reporting=4095 myfile.php

It does show up: "Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /srv/www/htdocs/entw/ldbkutty/myinfo.php on line 4"

Any ideas why the error_reporting(E_STRICT) has no effect here?
LVL 32
ldbkuttyAsked:
Who is Participating?
 
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
0
 
Richard QuadlingSenior Software DeveloperCommented:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

class myc_class
      {
      var $ttt;
      public $pub;
      protected $prot;
      private $priv;
      
      public function __construct()
            {
            $this->ttt = 2;
            }
      public function test()
            {
            echo $this->ttt;
            }
      }

echo 1;
$x = new myc_class();
$x->test();
echo 3;
var_dump($x);
?>

I'm on PHP 5.2.0-dev (cli) (built: Jul 12 2006 12:20:25)

and my output is ...

123object(myc_class)#1 (4) {
  ["ttt"]=>
  int(2)
  ["pub"]=>
  NULL
  ["prot:protected"]=>
  NULL
  ["priv:private"]=>
  NULL
}

In other words, var is now assumed to be public.

0
 
TeRReFCommented:
Add this under error_reporting and see if tht works...
 ini_set('display_errors', 'On');
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Richard QuadlingSenior Software DeveloperCommented:
I suspect your CLI version of PHP is different to your webservers version.

At the cli ...

php -v

and then see what version <?php phpinfo(); ?> reveals via your browser.
0
 
ldbkuttyAuthor Commented:
I do have 'display_errors' set to ON.

>> In other words, var is now assumed to be public.
Thats right, but  according to the "Note:" here: http://de3.php.net/manual/en/language.oop5.visibility.php#AEN5817 I should get the deprecated warning message if I have E_STRICT enabled, right?

>> I suspect your CLI version of PHP is different to your webservers version.
Its the same!

btw, how are you doing RQuadling ?
0
 
Richard QuadlingSenior Software DeveloperCommented:
There is no point in setting E_STRICT at run time as E_STRICT is only processed during parsing, before the code is run. E_STRICT must be set in the INI file.
0
 
Richard QuadlingSenior Software DeveloperCommented:
I'm doing well.

You?
0
 
Richard QuadlingSenior Software DeveloperCommented:
Just tested with PHP 5.2.0-dev (cli) (built: Jul 20 2006 12:20:26)

And it seems E_Strict is now amendable at run time!
0
 
ldbkuttyAuthor Commented:
I guessed the same, its a BUG !

Thank you. And I am fine too :-)
0
 
TertiumNonDaturCommented:
This is also strange and might be a problem in the same context:

class c1 {
    function test1() {
    }
}
class c2 {
    function test2() {
        c1::test1();         /* Critical line */
    }
}

Now this call produces a strict message:
c1::test1();
PHP Strict Standards:  Non-static method c1::test1() should not be called statically


However, these calls do not:
$x = new c2();
$x->test2();

I would have expected that the execution of the /* Critical line */
is interpreted as a static function call and should generate a
strict message, but it doesn't.





0
 
Richard QuadlingSenior Software DeveloperCommented:
Declare c1's method test1 as static and the issue is resolved.

<?php

class c1 {
    static function test1() {
    }
}
class c2 {
    function test2() {
        c1::test1();
    }
}

$x = new c2();
$x->test2();
?>
0
 
Richard QuadlingSenior Software DeveloperCommented:
With my PHP and this code ...

<?php

class c1 {
    function test1() {
    }
}
class c2 {
    function test2() {
        c1::test1();         /* Critical line */
    }
}

$x = new c2();
$x->test2();
?>

I get ...

Strict Standards: Non-static method c1::test1() should not be called statically, assuming $this from incompatible context in C:\er4.php on line 9


Using PHP 5.2.0-dev (cli) (built: Jul 20 2006 12:20:26)
0
 
TertiumNonDaturCommented:
OK, I admit, my PHP version is not the newest, latest, hypest:

php5 --version
PHP 5.0.3 (cgi) (built: Mar 22 2005 20:12:51)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies

@RQuadling: Actually, test1() should not be a static function.
So what I need is a strict message if somebody wants to use
this function in a static way (which should not be the case).

However, when this is fixed in newer PHP versions - that's what
I want :-).

Regards
0
 
Richard QuadlingSenior Software DeveloperCommented:
If it is being called as a static it has to be allowed a call as static, I think!
0
 
Richard QuadlingSenior Software DeveloperCommented:
"Tertium Non Datur" ? Nah. Ask any woman. Yes / No / Maybe. The third state ALWAYS exists and more often than not may be either of the other states simultaneously!
0
 
TertiumNonDaturCommented:
RQuadling wrote

> If it is being called as a static it has to be allowed a call as static, I think!

Sure, but this is not the point. The class definition might be MY CODE. And the caller might be SOMEONE ELSE who didn't look at the function definition exactly enough. And this other person SHOULD get the strict message, don't you think?

Regards
TertiumNonDatur (I am no woman ;-)
0
 
Richard QuadlingSenior Software DeveloperCommented:
If E_STRICT is enabled and you call a method statically and the method is NOT defined as static, then I get the error.

I think this is correct.

As far as documentation is concerned, that is why phpDoc exists. Makes a LOT of this sort of thing REALLY obvious.
0
 
TertiumNonDaturCommented:
YOU get the error with your PHP version. I DO NOT get the error (with my older PHP version). Got it?
0
 
Richard QuadlingSenior Software DeveloperCommented:
I think the E_STRICT is slightly wonky anyway. All sorts of things come out when they shouldn't and as you see, don't when they should!

0
All Courses

From novice to tech pro — start learning today.