[thelist] PHP conditionally create a class method?
Stephen Rider
evolt_org at striderweb.com
Wed Aug 27 18:24:01 CDT 2008
On Aug 27, 2008, at 12:05 PM, sbeam wrote:
> 'function' is evaluated at compile time. Therefore PHP is "seeing"
> your
> definition of 'myfunction' regardless of what conditional it is in.
Okay.
> You can't do
> class test {
> function foo() { function bar() { ... } }
> }
> and then call test::bar()
> in PHP anyway. bar() is only known within the scope of foo()
That statement is flatly in opposition to the O'Reilly PHP book. It
states (page 66):
*** quote ***
You can nest function declarations, but with limited effect. Nested
declarations do not limit the visibility of the inner defined
function, which may be called from anywhere in your program.
*** end quote ***
Just FYI, as your first point precludes using that method anyway.
> Instead, just use inheritance normally and define all your "missing
> functions"
> in parentclass, redefining as needed in the extensions.
>
> class parentclass {
> function a() { echo 'A '; }
> function b() { echo 'B '; }
> function c() { echo 'C '; }
> function d() { echo 'D '; }
> }
>
> class child extends parentclass {
> function a() { echo 'special A from kid! '; }
> }
Okay, _that_ was my main confusion. I thought that would result in
more "You've already defined that function" errors. I'll give that a
try.
if it doesn't work, I'll try create_function per Matt's suggestion.
Thanks.
Stephen
--
Stephen Rider
<http://striderweb.com/>
More information about the thelist
mailing list