if and else execute together! (class extends)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ehsanch
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2010 6:15 am

if and else execute together! (class extends)

Post by ehsanch »

i create a simple php script :

Code: Select all

 
<?php
class newclass {
    public function newfunc() {
        echo 'class exist';
    }
}
 
if (true) {
    class myclass1 extends newclass {}
}
else {
    class myclass2 extends newclass {}
}
 
$test = new myclass2;
$test->newfunc();
 
in browser i get
class exist
, but in cli i get
Fatal error: Class 'myclass2' not found in test.php on line 15
--------------------run with php vs php-cgi--------------------
[root@server]# php test.php
Fatal error: Class 'myclass2' not found in test.php on line 15

[root@server]# php-cgi test.php
X-Powered-By: PHP/5.2.6
Content-type: text/html
class exist

im astonished!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: if and else execute together! (class extends)

Post by requinix »

That could very well be a bug. The 5.2 branch is up to .13 I believe - upgrade to there and see if it still works like that.

But really: putting classes in a conditional block? Doesn't make sense.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: if and else execute together! (class extends)

Post by AbraCadaver »

Works as expected on 5.2.4.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ehsanch
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2010 6:15 am

Re: if and else execute together! (class extends)

Post by ehsanch »

it work on another system with 5.2.6 and worked on this system before.
suddenly i get this ./
i think there is a configuration somewhere...
ehsanch
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2010 6:15 am

Re: if and else execute together! (class extends)

Post by ehsanch »

Finally i found the cause after 1 full day.
this was because of XCache !
removing it solve problem.
hope save someones time...
Post Reply