2022/11/01: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
(Created page with "{{page/date}} ==PHP namespace issue== So, this is just kind of weird. I don't know yet if it's a bug or just something I've overlooked. Code: <syntaxhighlight lang=php> <?php...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 18: Line 18:


The major clue, I think, is that if I replace all the "FD" aliases with "\ferret\data", I get the ''exact same error'' -- which suggests that the problem is actually in some other file.
The major clue, I think, is that if I replace all the "FD" aliases with "\ferret\data", I get the ''exact same error'' -- which suggests that the problem is actually in some other file.
...yep, that's what it was! The parent-class had been moved from a file with a different namespace, so needed to use the "FD\" alias-prefix, into a file with the "ferret\data" namespace, which did not need the alias and so did not have it defined. ...but the error message blamed the child-class. So typical of that generation...
==Data-Mangling Syntax==
How about something like...
{{arg|array_var}}({{arg|var_for_key}},{{arg|var_for_val}}){ ...code... }
That means "for each element in {{arg|array_var}}, assign the element's name to the variable {{arg|var_for_key}} and value to {{arg|var_for_val}} and then execute the code in the curly braces".
Why not just <syntaxhighlight lang=php inline>foreach ($array_var as $key => $val) { ...code>... }</syntaxhighlight, as in PHP? I don't know, except that seems more complicated and less succinct. I want to keep the syntax (and parser code) simple.

Latest revision as of 13:52, 1 November 2022

Tuesday, November 1, 2022 (#305)
Monday Tuesday Wednesday

PHP namespace issue

So, this is just kind of weird. I don't know yet if it's a bug or just something I've overlooked.

Code:

<?php namespace greenmine\config;

use ferret\data as FD;

class cServerSpec extends FD\cDBServerSpec {}

class csDataSpec extends FD\csSpecs {

    static protected function GetSpec(string $sKey) : cServerSpec {

Error: "Class ferret\data\FD\cDBServerSpec was requested but is neither loaded nor registered with the Class Loader."

The major clue, I think, is that if I replace all the "FD" aliases with "\ferret\data", I get the exact same error -- which suggests that the problem is actually in some other file.

...yep, that's what it was! The parent-class had been moved from a file with a different namespace, so needed to use the "FD\" alias-prefix, into a file with the "ferret\data" namespace, which did not need the alias and so did not have it defined. ...but the error message blamed the child-class. So typical of that generation...

Data-Mangling Syntax

How about something like...

<array_var>(<var_for_key>,<var_for_val>){ ...code... }

That means "for each element in <array_var>, assign the element's name to the variable <var_for_key> and value to <var_for_val> and then execute the code in the curly braces".

Why not just <syntaxhighlight lang=php inline>foreach ($array_var as $key => $val) { ...code>... }</syntaxhighlight, as in PHP? I don't know, except that seems more complicated and less succinct. I want to keep the syntax (and parser code) simple.