# Is this behavior expected?

- Thread: https://externals.io/message/49841
- Original archive: https://news-web.php.net/php.internals/49841
- Started by Jingcheng Zhang on 2010-10-03T05:40:10+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49841 — Jingcheng Zhang — 2010-10-03T05:40:10+00:00

URL: https://externals.io/message/49841#49841

Hello internals,

I've occurred an inconsistent problem:

<?php
C::f();
abstract class C {
    public static function f() {
        echo 'foo';
    }
}
?>

This works and print "foo".

<?php
C::f();
interface I {}
abstract class C implements I {
    public static function f() {
        echo 'foo';
    }
}
?>

The result is "Fatal error: Class 'C' not found". Is this result expected?
Why?

-- 
Best regards,
Jingcheng Zhang
Beijing, P.R.China

---

## #49842 — Stas Malyshev — 2010-10-03T05:59:46+00:00

URL: https://externals.io/message/49841#49842 · In reply to: #49841

Hi!

> The result is "Fatal error: Class 'C' not found". Is this result expected?

Yes. Define your classes before using them, or use autoloading.

> Why?

(Highly technical details) Because C can't be early-bound on compile 
time due to the dependency on the interface and thus at the time of the 
call it's not defined, because the definition happens at run-time when 
control arrives to the point of class definition.
Since early binding is quite complex, it is best to assume classes 
always are defined at run-time and define them before use.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #49843 — Jingcheng Zhang — 2010-10-03T06:19:42+00:00

URL: https://externals.io/message/49841#49843 · In reply to: #49842

Hi Stas,

Got it. Thanks for your detailed explanation :-)

2010/10/3 Stas Malyshev <smalyshev@sugarcrm.com>

> Hi!
>
>
>  The result is "Fatal error: Class 'C' not found". Is this result expected?
> > […]
>
> Yes. Define your classes before using them, or use autoloading.
>
>  Why?
> > […]
>
> (Highly technical details) Because C can't be early-bound on compile time
> due to the dependency on the interface and thus at the time of the call it's
> not defined, because the definition happens at run-time when control arrives
> to the point of class definition.
> Since early binding is quite complex, it is best to assume classes always
> are defined at run-time and define them before use.
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>



-- 
Best regards,
Jingcheng Zhang
Beijing, P.R.China
