C
C
coderisimo2016-09-02 16:07:47
PHP
coderisimo, 2016-09-02 16:07:47

PHP. From one class is not visible to another. How to fix?

there is such a structure. The dbclass.php file is available, otherwise there would be errors immediately upon startup. However, when I try to use the class from the included file, I get the error Fatal error: Class 'Blackjack\db_write' not found in C:\OpenServer\domains\blackjack\blackjack\blackjack.php
It is clear that it is not being looked for there. ((

<?php
namespace Blackjack;
require ('./dbclass.php');

class BlackJack {

 $e = new ClasFrom_dbclass; 

}

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2016-09-02
@coderisimo

namespace Blackjack;
$e = new ClasFrom_dbclass;

Namespace visible? Well, that's the problem .
Your class is requested as ClasFrom_dbclassin the current namespace \Blackjack . This means the full name of the class \Blackjack\ClasFrom_dbclass. But in fact, the class ClasFrom_dbclassis apparently located in the global namespace. So you need to address it accordingly $e = new \ClasFrom_dbclass;(attention to the slash).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question