Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:49:02+00:00 2026-05-31T05:49:02+00:00

a.php <?php echo AAA\n; if(class_exists(‘NotImplementedException’)) { echo BBB\n; return; echo DDD\n; } echo CCC\n;

  • 0

a.php

<?php

echo "AAA\n";
if(class_exists('NotImplementedException')) {
    echo "BBB\n";
    return;
    echo "DDD\n";
}

echo "CCC\n";

/**
 * Thrown when a feature is not yet implemented.
 */
class NotImplementedException extends Exception {}

b.php

<?php
include 'a.php';
include 'a.php';

When I run b.php I get:

AAA
BBB
PHP Fatal error:  Cannot redeclare class NotImplementedException in /home/mark/Tests/IncludeTwice/a.php on line 15

What’s going on here? The output I would expect is

AAA
CCC
(class gets declared for first time)
AAA
BBB
(execution stops)

To those saying “the interpreter scans and parses the whole file first”: then why does this work?:

<?php

class A{}

if(!class_exists('A')) {
    class A{}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:49:03+00:00Added an answer on May 31, 2026 at 5:49 am

    I think one part is a bug…

    The PHP interpreter works differently if you are extending a class.

    This works:

    <?php
    
    class a {}
    exit();
    class a extends Exception {}
    
    ?>
    

    This does not:

    <?php
    
    class a extends Exception {}
    exit();
    class a {}
    
    ?>
    

    From what I can see in the PHP 5.4.0 source, there are two different functions that handle the binding of classes: do_bind_class:4494 for standalone classes and do_bind_inherited_class:4533 for inherited classes (ones that use the extend keyword).

    The stand-alone function has a conditional that ignores duplicate class definitions at compile time in case it is never hit at runtime. The inherited class version is missing this conditional (maybe on purpose, maybe not).

    I would patch the inherited function to have the same conditional, test and submit to the developers.

    And the other part is a feature…

    As for your conditional class piece: I believe that PHP will load your class at compile-time if it is declared at global scope, but if it is contained inside a block, it will not be loaded until it is executed.

    This works:

    <?php
    
    $a = new A();
    
    //{
        class A {}
    //}
    
    ?>
    

    This doesn’t work, even though it is logically identical:

    <?php
    
    $a = new A();
    
    {
        class A {}
    }
    
    ?>
    

    When you combine these two pieces of functionality, your problem arises since your class is both an inherited class and declared at global scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php $array = array('aaa', 'bbb', 'aaa', 'ccc', 'ddd', 'ccc', 'eee'); foreach($array as $a){ echo
how to use simple_html_dom get each value aaa , bbb , ccc , ddd
i have for example: $one = 'aaa bbb ccc sss ddd www'; $two =
PHP Echo or Print functions does not show anything when php is busy with
PHP echo function is not outputing strings in the format of html tag like
I run this script: define('SECRET', vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5); echo sha1(SECRET . 'zcbkeyky' . 'aaa@bbb.com') . \n;
php code: <?php echo json_encode(glob(photos-.$_GET[folder].'/*.jpg')); ?> it return : [photos-animaux\/ani-01.jpg,photos-animaux\/ani-02.jpg,photos-animaux\/ani-02b.jpg,photos-animaux\/ani-03.jpg,photos-animaux\/ani-04.jpg,photos-animaux\/ani-05.jpg,photos-animaux\/ani-06.jpg,photos-animaux\/ani-07.jpg,photos-animaux\/ani-08.jpg,photos-animaux\/ani-09.jpg,photos-animaux\/ani-10.jpg,photos-animaux\/ani-11.jpg,photos-animaux\/ani-12.jpg,photos-animaux\/ani-13.jpg,photos-animaux\/ani-14.jpg] Which is ALMOST perfect,
This is where i put a popup box into echo <tr><td>.$set['Name'].</td><td>.$set['Position'].</td><td><select name='aaa'><option value='default'>Not Share</option><option
This if(is_object($value)) echo 'AAA'; if(gettype($value)==='object') echo 'BBB' Prints 'BBB'. Specifically, value is __PHP_Incomplete_Class Object
<?php echo isset($_GET[name])?$_GET['name']:'ddd'; ?> <?php ... $url = (http://localhost/web12/directory/list=.$_GET['name'].); //echo $url; ... ?> <form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.