V
V
Vasily2021-09-29 00:46:55
PHP
Vasily, 2021-09-29 00:46:55

How to access class method in $GLOBALS array?

Hello! Can you please tell me how to properly access the class method in the $GLOBALS array? My code throws an error:

Fatal error: Uncaught Error: Class "My\Icon" not found in /www/tpl.php...


tpl.php:
use My\Icon;

$GLOBALS['messengers'] = [
  [
    'title' => 'Telegram',
    'icon'  => Icon::SVG( 'telegram' ),
  ]

  //...
];


icon.php:
namespace My;

class Icon {
  protected static array $icons = [
    'telegram' => '<svg>...</svg>'
  ];

  //...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2021-09-29
@fa70000077

The array file does not know anything about the class, since the file with this class is not imported.
require_once('path/to/My/Icon.php');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question