1 | <?php |
||
2 | |||
3 | namespace DB; |
||
4 | |||
5 | use PDO; |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | class backup |
||
8 | { |
||
9 | /** |
||
10 | * \DB\pdo instance. |
||
11 | * |
||
12 | * @var \DB\pdo |
||
13 | */ |
||
14 | private $pdo; |
||
15 | |||
16 | public function __construct(pdo $pdo) |
||
17 | { |
||
18 | $this->pdo = $pdo; |
||
0 ignored issues
–
show
It seems like
$pdo of type PDO is incompatible with the declared type DB\pdo of property $pdo .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
19 | } |
||
20 | |||
21 | public function backup() |
||
22 | { |
||
23 | $DBH = $this->pdo->pdo(); |
||
24 | $show = $DBH->query('SHOW TABLES'); |
||
25 | $tables = []; |
||
26 | while ($row = $show->fetch(PDO::FETCH_NUM)) { |
||
27 | $tables[] = $row[0]; |
||
28 | } |
||
29 | $table_creation = ''; |
||
30 | foreach ($tables as $table) { |
||
31 | $result = $DBH->query("SELECT * FROM $table"); |
||
32 | $num_fields = $result->columnCount(); |
||
0 ignored issues
–
show
|
|||
33 | $num_rows = $result->rowCount(); |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | $pstm2 = $DBH->query("SHOW CREATE TABLE $table"); |
||
36 | $row2 = $pstm2->fetch(PDO::FETCH_NUM); |
||
37 | $ifnotexists = str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $row2[1]); |
||
38 | $table_creation .= "\n\n" . $ifnotexists . ";\n\n"; |
||
39 | } |
||
40 | header('Content-Type: application/json'); |
||
41 | echo $table_creation; |
||
42 | exit; |
||
0 ignored issues
–
show
|
|||
43 | } |
||
44 | } |
||
45 |
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: