How to Autoload PHP Files & Classes (PSR-4) - PHP Composer Tutorial

preview_player
Показать описание
In this video tutorial I'll be demonstrating how to autoload your PHP files (or classes) using PSR-4 and Composer. This is very easy and convenient to do.

Support me on Patreon:

For your reference, check this out:

Follow me on Twitter @dcodeyt!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Thank you so much! Very clear, very simple, very useful.

HugoGuzmanC
Автор

Hi, thanks for this short but wonderful video, it saved the day for me. Thanks

emekaokafor
Автор

Now it's working.
namespace is camel case.
if folder is data, the namespace need to be MyApp\data

lucasdanielbeltrame
Автор

Thanks so much! This is really simple explanation :)

alexanderyarkin
Автор

yes yes bro Quick and Simple nice
and I subscribed please continue make things like this

joeljohn
Автор

It's just wonderful work. Very very thank you, bro...💯

TechnTuts
Автор

i watch 1 billion video and i don't understand but this video help me so much thank u, please can you explain about license types and minimum stability

TITAN-sveg
Автор

Hii, can u do more php tutorial. I really like your explanation its clear and easy to follow, thankyouu

ikhsan
Автор

Are you demonstrating this on a Windows system? I found out that on a linux system it is significant to match the names of the folders with the namespace.
Folder names should be Data (not data), Game (not game) and Player (not player)

"2. Specification

The term "class" refers to classes, interfaces, traits, and other similar structures.
A fully qualified class name has the following form:


The fully qualified class name MUST have a top-level namespace name, also known as a "vendor namespace".
The fully qualified class name MAY have one or more sub-namespace names.
The fully qualified class name MUST have a terminating class name.
Underscores have no special meaning in any portion of the fully qualified class name.
Alphabetic characters in the fully qualified class name MAY be any combination of lower case and upper case.
All class names MUST be referenced in a case-sensitive fashion.
When loading a file that corresponds to a fully qualified class name ...

A contiguous series of one or more leading namespace and sub-namespace names, not including the leading namespace separator, in the fully qualified class name (a "namespace prefix") corresponds to at least one "base directory".
The contiguous sub-namespace names after the "namespace prefix" correspond to a subdirectory within a "base directory", in which the namespace separators represent directory separators. 

***
The subdirectory name MUST match the case of the sub-namespace names.
***

The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.
Autoloader implementations MUST NOT throw exceptions, MUST NOT raise errors of any level, and SHOULD NOT return a value."

wilbertvanbakel
Автор

Great video. Can you please also guide how to add a router in this and also how to override classes ?

tapanbhanot
Автор

so the word "MyApp" means for namespace?

iGmng
Автор

What to do when I have this folder structure ... src\data-main ... I mean, do the folders have to be single worded? Folders with dashes are not working ... any idea?

htmlfivedev
Автор

You need to name your dirs same as in namespace (Game, Data) or you will get "...does not comply with psr-4 autoloading standard. Skipping." error when running on Linux.

amigaworkbench
Автор

class does not comply with psr-4 autoloading standard. Skipping. I don't know mate. It just plain doesn't work.

JakeAikens
Автор

Thank you for very informative video, may I ask what is called the extension that automatically adds use keyword with the path when class being instantiated?

brtj
Автор

*Fatal error: Uncaught Error: Class not found*

timhoward
Автор

hi i tried this having error please help me out Fatal error: Uncaught Error: Class 'inc\beheader' not found in 4 Stack trace: #0 {main} thrown in on line 4

ifredpingplay
Автор

What keyboard do you use? The sound is so satisfying.

franciscalizo
Автор

Sir please make 1 more video, how to export excel sheet from PhpSpreadsheet library in Codiginitor 4.1.1.

MsAlokranjan
Автор

Using realpath with require_once I'm getting an error saying
Warning: failed to open stream: Permission denied in on line 3

raahimfareed