Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Podstawy: przestrzenie nazw
spidero
post 3.12.2018, 11:56:22
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 9.03.2006

Ostrzeżenie: (0%)
-----


Probuje skorzystac z bilbioteki https://github.com/Josantonius/PHP-Session

I o ile wszystko jest proste i dziala

  1. require 'config.php';
  2.  
  3. use Josantonius\Session\Session;
  4.  
  5. $prefix = 'sespref';
  6.  
  7. Session::setPrefix($prefix);
  8.  
  9.  
  10. $tst = Session::getPrefix();
  11.  
  12. print_r($tst);


to jesli nie chcialbym uzywac use w kazdym pliku php tylko przeniesc do includowanego pliku

  1. require 'config.php';


to juz nie widac przestrzeni nazw i skrypt pluje:

  1. PHP Fatal error: Uncaught Error: Class 'Session' not found in index.php:6\nStack trace:\n#0 {main}\n thrown in index.php


jak sobie z tym poradzic jesli chcialbym zdeklarowac use tylko w jednym pliku (config.php) ?

Ten post edytował spidero 3.12.2018, 12:14:55


--------------------
Forum PLD Linux
Go to the top of the page
+Quote Post
Pyton_000
post 3.12.2018, 12:57:21
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Dokumentacja prawdę Ci powie...

http://php.net/manual/en/language.namespaces.importing.php

Cytat
Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.


Ten post edytował Pyton_000 3.12.2018, 12:57:48
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 10:27