# PHP4 -> PHP5 incompatibility - classes must be declared before being used

- Thread: https://externals.io/message/9035
- Original archive: https://news-web.php.net/php.internals/9035
- Started by Marc Richards on 2004-04-11T05:47:23+00:00
- Messages: 8
- 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

---

## #9035 — Marc Richards — 2004-04-11T05:47:23+00:00

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

Hi All,

I have a couple question re: {subject}.

Can anybody point me to some info on why this change was neccessary (not 
complaining, just curious).  I did some searching and it seems to relate 
to objects that use interfaces...but that is all I could find.  If it is 
too complex to explain that is fine; I just want to know whether I 
should keep looking or not.

Are there any edge cases where it would not be impossible to satisfy 
this requirement...say some complex interdependence between two or more 
classes. Sorry I know this is very hand-wavvy but I don't have enough 
OOP experience to come up with a good example.

I read that for simple cases, instantiation before declaration will 
work...does/will this cause an `E_STRICT` error?

The primary reason for my curiosity is that I recently started putting 
PHP functions that only get used on one page at the end of the page (and 
therefore calling the function before it is defined).  While this 
greatly enhanced readibility, I was a little wary of this method, 
especially since I haven't really seen anybody else doing it.  Is there 
an inherent problem with this method for functions?  I guess the 
alternative would be to put it an included file (even though it is only 
included on one page).  Is that what most people do?

Along those lines, is there any performance penalty for using 
__autoload() to load my php classes if I am using a code cache like APC?

Does __autoload() work for functions?


Marc

---

## #9046 — Marcus Boerger — 2004-04-11T21:16:32+00:00

URL: https://externals.io/message/9035#9046 · In reply to: #9035

Hello Marc,

Sunday, April 11, 2004, 7:47:23 AM, you wrote:

> Hi All,

> I have a couple question re: {subject}.

> Can anybody point me to some info on why this change was neccessary (not 
> complaining, just curious).  I did some searching and it seems to relate 
> to objects that use interfaces...but that is all I could find.  If it is 
> too complex to explain that is fine; I just want to know whether I 
> should keep looking or not.

The new OO features of PHP 5 made that necessary. Generally if you
do not use any of them (interfaces, abstract, final) the engine will
(should) still be able to do everything at compile time so that you
can use your classes before usage.

> Are there any edge cases where it would not be impossible to satisfy 
> this requirement...say some complex interdependence between two or more 
> classes. Sorry I know this is very hand-wavvy but I don't have enough 
> OOP experience to come up with a good example.

> I read that for simple cases, instantiation before declaration will 
> work...does/will this cause an `E_STRICT` error?

no but probabla something to discuss since maybe later it won't work
anymore and it is 'not so good practise' or better say not recommended
usage.

> The primary reason for my curiosity is that I recently started putting 
> PHP functions that only get used on one page at the end of the page (and 
> therefore calling the function before it is defined).  While this 
> greatly enhanced readibility, I was a little wary of this method, 
> especially since I haven't really seen anybody else doing it.  Is there 
> an inherent problem with this method for functions?  I guess the 
> alternative would be to put it an included file (even though it is only 
> included on one page).  Is that what most people do?

I guesso but includes of course come with some speed penalty.

> Along those lines, is there any performance penalty for using 
> __autoload() to load my php classes if I am using a code cache like APC?

Ask george

> Does __autoload() work for functions?

nope


-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #9329 — Luna Kid — 2004-04-17T17:22:26+00:00

URL: https://externals.io/message/9035#9329 · In reply to: #9046

> > […]
>
> nope

But could? (Or would, some day?)

Cheers,
Sz.

---

## #9335 — Derick Rethans — 2004-04-17T22:53:24+00:00

URL: https://externals.io/message/9035#9335 · In reply to: #9329

> > […]
>
> But could? (Or would, some day?)

Technically it is possible, but we ain't going to add this.

Derick

---

## #9336 — Luna Kid — 2004-04-18T09:42:45+00:00

URL: https://externals.io/message/9035#9336 · In reply to: #9335

> > […]
>
> Technically it is possible, but we ain't going to add this.

I see, thanks.

May I also ask the reasons?

(I bet anyone a dead rat that *lots* of authors of simple
plugin-based designs (not needing real OOP stuff) would
welcome function autoloading. In fact, many of us, I'm sure,
had wondered cluelessly about how to do it with __autoload,
before wondering cluelessly about why was that support
omitted after all...)

Thanks again,
Sz.

---

## #9337 — Ilya Sher — 2004-04-18T10:59:06+00:00

URL: https://externals.io/message/9035#9337 · In reply to: #9336

Luna Kid wrote:

[snip]
> (I bet anyone a dead rat that *lots* of authors of simple
> plugin-based designs (not needing real OOP stuff) would
> welcome function autoloading. In fact, many of us, I'm sure,
> had wondered cluelessly about how to do it with __autoload,
> before wondering cluelessly about why was that support
> omitted after all...)
> 
> Thanks again,
> Sz.
> 

I've actually impemented something very similar in PHP.
Thereis list of funcs with the filenames they reside.
(List is compacted.)
The limitation if my implementation is that each func.
may only have one argument so i just pass a hash and
use `extract()`.

---

## #9343 — Marc Richards — 2004-04-18T16:57:37+00:00

URL: https://externals.io/message/9035#9343 · In reply to: #9046

Marcus Boerger wrote:

> > […]
> 
> 
> Ask george
> 

Does anyone know when __autoload() gets invoked? Is it during code 
compilation or at runtime?  Has anyone tested __autoload() with a code 
cache like APC or ZPS?


Marc

---

## #9383 — Friedhelm Betz — 2004-04-19T15:23:51+00:00

URL: https://externals.io/message/9035#9383 · In reply to: #9046

> Hello Marc,
[...]
> > […]
>
> no but probabla something to discuss since maybe later it won't work
> anymore and it is 'not so good practise' or better say not
> recommended usage.
>

I really like it would produce an `E_STRICT` error, see
http://bugs.php.net/bug.php?id=27440

Regards
Friedhelm
