chapter-three / oophp-training

Training materials for Object Oriented PHP Training
24 stars 15 forks source link

Add: namespace and use keywords #3

Closed 13rac1 closed 7 years ago

13rac1 commented 10 years ago

If this training is going to be re-used, one of the lessons should cover the namespace and the use keywords since both are relevant to Drupal 8.

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

namespace Drupal\demo\Plugin\Block;

use Drupal\block\BlockBase;
use Drupal\Core\Session\AccountInterface;

src: http://www.sitepoint.com/building-drupal-8-module-blocks-forms/

kscheirer commented 7 years ago

Looks like this was added in 7.md. However, that section could use some excercises.

Suggested exercise:

  • Add a namespace to the top of your file, this will put all classes defined in that file into that namespace.
  • Add a constant or static variable to one of your classes / interfaces.
  • Print the constant/static by calling the full namepaced name of your class.
  • Add a use statement, and print your constant/static again using the short namespace of your class.

This is now PR #11

13rac1 commented 7 years ago

Ah ha! Yes it was mostly fixed in https://github.com/chapter-three/oophp-training/commit/97230c27b35eedd9ca493e429ca655e2ab64cd5b

You can git commit --amend #11 to close this issue IMO.

mrf commented 7 years ago

Merged #11 thanks for the addition!