1

There is a class which handles the internationalization.

<?php

class Language{
    // ...
}

Now I created a renderer.php file which should handle all injections for HTML.

<?php
namespace Renderer;

include_once '../language.php';

function drawUserList(){
    // ...
    $group = Language::translate($groupName);
   // ...
}

In this file I need my Language class. But my compiler throws the following error message:

Undefined type 'Renderer\Language'.

The Language class is not part of a namespace. Why adds PHP a namespace to it? And why I am not able to use the class in my namespace function?

PHP Version 7.4.26

1

1 Answer 1

2

You have to use the keywork use:

namespace Renderer;
use Language; // indicate to use \Language

include_once '../language.php';

function drawUserList(){
    // ...
    $group = Language::translate($groupName);
   // ...
}

or use $group = \Language::translate().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.