Two Parser Passes

Two Parser Passes

am 31.10.2009 21:51:20 von Daniel Kolbo

Hello,

Is it possible to get a list (array) of classes not found in a script
before the fatal error exits the parser. I realize that PHP parses the
script twice. It would be nice at the end of the first parsing pass to
check to see which classes haven't been defined (yet), so that I could
define them before the second pass. This way I could load only those
classes a script needs.

Thanks in advance,
dK
`

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Two Parser Passes

am 31.10.2009 22:21:48 von Steve

Daniel Kolbo wrote:
> Hello,
>
> Is it possible to get a list (array) of classes not found in a script
> before the fatal error exits the parser. I realize that PHP parses the
> script twice. It would be nice at the end of the first parsing pass to
> check to see which classes haven't been defined (yet), so that I could
> define them before the second pass. This way I could load only those
> classes a script needs.
>
> Thanks in advance,
> dK
> `
>
It sounds like you are looking for autoload:
http://www.php.net/manual/language.oop5.autoload.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Two Parser Passes

am 31.10.2009 23:02:43 von Daniel Kolbo

Steve wrote:
> Daniel Kolbo wrote:
>> Hello,
>>
>> Is it possible to get a list (array) of classes not found in a script
>> before the fatal error exits the parser. I realize that PHP parses the
>> script twice. It would be nice at the end of the first parsing pass to
>> check to see which classes haven't been defined (yet), so that I could
>> define them before the second pass. This way I could load only those
>> classes a script needs.
>>
>> Thanks in advance,
>> dK
>> `
>>
> It sounds like you are looking for autoload:
> http://www.php.net/manual/language.oop5.autoload.php
>

Mr. Steve that's pretty cool. Thanks.

Is there a similar type function for autoloading undefined functions?

Thanks,
dK
`

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Two Parser Passes

am 04.11.2009 15:41:00 von Nathan Rixham

Daniel Kolbo wrote:
> Steve wrote:
>> Daniel Kolbo wrote:
>>> Hello,
>>>
>>> Is it possible to get a list (array) of classes not found in a script
>>> before the fatal error exits the parser. I realize that PHP parses the
>>> script twice. It would be nice at the end of the first parsing pass to
>>> check to see which classes haven't been defined (yet), so that I could
>>> define them before the second pass. This way I could load only those
>>> classes a script needs.
>>>
>>> Thanks in advance,
>>> dK
>>> `
>>>
>> It sounds like you are looking for autoload:
>> http://www.php.net/manual/language.oop5.autoload.php
>>
>
> Mr. Steve that's pretty cool. Thanks.
>
> Is there a similar type function for autoloading undefined functions?
>
> Thanks,
> dK
> `

not afaik, but you should be able to hack it by catching errors,
checking for undefined functions then loading your.lib.php file

imho it'd make more sense to wrap misc functions in a class or two as
static methods though then you can take advantage of the autoloading.

also if you can use spl autoloading and registration so it plays nice
with other libs.

regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php