and let’s assume the following content of Bar.php:
// Bar.phpnamespaceOtherDir;useSomeDir\Foo;// This now conflicts the class OtherDir\Foo
If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the
same runtime, you will see a PHP error such as the following:
PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as OtherDir/Foo.php does not necessarily have to be loaded and the
error is only triggered if it is loaded before OtherDir/Bar.php, this problem
might go unnoticed for a while. In order to prevent this error from surfacing,
you must import the namespace with a different alias:
// Bar.phpnamespaceOtherDir;useSomeDir\FooasSomeDirFoo;// There is no conflict anymore.
Loading history...
8
9
/**
10
* Mautic representation
11
*/
12
class Mautic
13
{
14
/**
15
* Mautic base (root) URL
16
*
17
* @var string
18
*/
19
protected $baseUrl;
20
21
/**
22
* Mautic Contact
23
*
24
* @var Contact
25
*/
26
protected $contact;
27
28
/**
29
* Mautic Contact Cookie
30
*
31
* @var Cookie
32
*/
33
protected $cookie;
34
35
/**
36
* Constructor
37
*
38
* @param string $baseUrl
39
*/
40
26
public function __construct($baseUrl)
41
{
42
26
$this->baseUrl = rtrim(trim($baseUrl), '/');
43
26
$this->cookie = new Cookie;
44
26
$this->contact = new Contact($this->cookie);
45
26
}
46
47
/**
48
* Returns Mautic's base URL
49
*
50
* @return string
51
*/
52
6
public function getBaseUrl()
53
{
54
6
return $this->baseUrl;
55
}
56
57
/**
58
* Returns new Mautic Form representation object
59
*
60
* @param int $id
61
*
62
* @return Form
63
*/
64
10
public function getForm($id)
65
{
66
10
return new Form($this, $id);
67
}
68
69
/**
70
* Sets the Mautic Contact if you want to replace the default one
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: