2022/11/01

From Woozle Writes Code
Revision as of 13:35, 1 November 2022 by Woozle (talk | contribs)
Jump to navigation Jump to search
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!

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.