PHP namespaces and “use”

The use operator is for giving aliases to names of classes, interfaces or other namespaces. Most use statements refer to a namespace or class that you’d like to shorten: use My\Full\Namespace; is equivalent to: use My\Full\Namespace as Namespace; // Namespace\Foo is now shorthand for My\Full\Namespace\Foo If the use operator is used with a class or … Read more

Superiority of unnamed namespace over static?

You’re basically referring to the section ยง7.3.1.1/2 from the C++03 Standard, The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative. Note that this paragraph was already removed in C++11. static functions are per standard no longer deprecated! Nonetheless, unnamed namespace‘s are superior to … Read more

How do I create a namespace package in Python?

TL;DR: On Python 3.3 you don’t have to do anything, just don’t put any __init__.py in your namespace package directories and it will just work. On pre-3.3, choose the pkgutil.extend_path() solution over the pkg_resources.declare_namespace() one, because it’s future-proof and already compatible with implicit namespace packages. Python 3.3 introduces implicit namespace packages, see PEP 420. This … Read more

Visibility of global variables in imported modules

Globals in Python are global to a module, not across all modules. (Many people are confused by this, because in, say, C, a global is the same across all implementation files unless you explicitly make it static.) There are different ways to solve this, depending on your actual use case. Before even going down this … Read more

Python ElementTree module: How to ignore the namespace of XML files to locate matching element when using the method “find”, “findall”

Instead of modifying the XML document itself, it’s best to parse it and then modify the tags in the result. This way you can handle multiple namespaces and namespace aliases: from io import StringIO # for Python 2 import from StringIO instead import xml.etree.ElementTree as ET # instead of ET.fromstring(xml) it = ET.iterparse(StringIO(xml)) for _, … Read more

Why can’t I forward-declare a class in a namespace using double colons?

You’re getting correct answers, let me just try re-wording: class Namespace::Class; Why do I have to do this? You have to do this because the term Namespace::Class is telling the compiler: …OK, compiler. Go find the namespace named Namespace, and within that refer to the class named Class. But the compiler doesn’t know what you’re … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)