Troubleshooting The use statement with non-compound name ... has no effect
PHP's use
isn't the same as C++'s using namespace
; it allows you to define an alias, not to "import" a namespace and thus henceforth omit the namespace qualifier altogether.
So, you could do:
use Blog\Article as BA;
... to shorten it, but you cannot get rid of it entirely.
Consequently, use Blog
is useless, but I believe you could write:
use \ReallyLongNSName as RLNN;
Note that you must use a leading \
here to force the parser into knowing that ReallyLongNSName
is fully-qualified. This isn't true for Blog\Article
, which is obviously already a chain of namespaces:
Note that for namespaced names (fully qualified namespace names containing namespace separator, such as
Foo\Bar
as opposed to global names that do not, such asFooBar
), the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.
- http://php.net/manual/en/language.namespaces.importing.php
Laravel: The use statement with non-compound name 'Cache' has no effect
Just remove use Cache; from your routes.php. It is not needed there as file itself is not associated with specific namespace. Once you remove it you will not see that warning again.
Laravel/Composer: The use statement with non-compound name
If you are not within a namespace (i.e. you are in the root namespace), and the class you want to use also is not in a namespace (i.e. also in the root namespace), then using use
makes no sense, because the code will work the same without it. You are not importing anything with this statement.
Composer has nothing to do with this, neither has any other autoloading. It's how PHP works by itself.
Laravel php artisan db:seed leads to use statement error
In PHP the use statement is more of an alias than import. So since the ClassesTableSeeder class isn't in a defined namespace, you don't need to import the DB class. As a result you can remove use DB entirely.
Laravel: php artistan migrate : The use statement with non-compound name 'IlluminateDatabaseMigrationsMigration' has no effect
You might have copied and pasted bad code like I did to get that same error.
In your migration php file change the line that has:
use IlluminateDatabaseMigrationsMigration
to say:
use Illuminate\Database\Migrations\Migration
The slashes didn't copy from your source code.
PHP error while (1) Importing a non-compound namespace or (2) Importing any namespace to instantiate a class
If I understand you correctly, I think this is what you are looking for?
namespace b {
class my_class{
function test() {
echo 'here';
}
}
}
namespace a {
use b as c;
// FQN
(new \b\my_class())->test();
// Aliased
(new c\my_class())->test();
}
I would personally never write code like this, nor did I know that you can alias a namespace, but it appears to work.
Demo: https://3v4l.org/79Dmg
Edit
Here's a version with two files and without bracketed namespaces
<?php
// file b.php
namespace b;
class my_class
{
function test()
{
echo 'here';
}
}
<?php
// file a.php
namespace a;
use b as c;
require_once 'b.php';
// FQN
(new \b\my_class())->test();
// Aliased
(new c\my_class())->test();
Related Topics
How to Remove All Numbers from String
PHP Get How Many Days and Hours Left from a Date
Interview Question: in PHP, Is 123==0123
MySQL Binary Storage Using Blob VS Os File System: Large Files, Large Quantities, Large Problems
Using Curl in PHP with Client Certificate and Private Key in Separate Files
Installing Imagemagick Extension with PHP/Windows
How to Check If a Longitude/Latitude Point Is Within a Range of Coordinates
Change Woocommerce Default Password Security Level
PHP Image Resize on the Fly VS Storing Resized Images
Mp4 Plays When Accessed Directly, But Not When Read Through PHP, on iOS