Since everyone is in the "namespace" frame of mind, is there a
possibility of a "namespace" access modifier?
The way I envision this working is that if for example:
namespace Foo;
class Bar {
nsprotected $_someProperty = null;
}
(or some other equivalent grammer)
Would allow the property Foo::Bar::$_someProperty to be accessed from
any class that has implemented a class from the Foo namespace.
Reaching for straws or is this a possibility?
-ralph
Would this not do the same thing and perhaps be easier to implement:
namespace Foo;
protected $var;
class Bar {
}
thus allowing use of private public protected before variables, and hell
why not classes aswell.
private = only methods, code, classes in namespace Foo have access
protected = only methods, code, classes in namespace Foo or children
Foo::Too have access
public = everybody
the same inheritance rules etc as classes.. makes sence :) and great idea!
got my vote, especially with the braces in namespaces!
namespace Foo; {
protected $var;
public class Extender {
public function __construct() {
......
}
}
}
Nathan
Ralph Schindler wrote:
Since everyone is in the "namespace" frame of mind, is there a
possibility of a "namespace" access modifier?The way I envision this working is that if for example:
namespace Foo;
class Bar {
nsprotected $_someProperty = null;
}(or some other equivalent grammer)
Would allow the property Foo::Bar::$_someProperty to be accessed from
any class that has implemented a class from the Foo namespace.Reaching for straws or is this a possibility?
-ralph
Hello Ralph,
I don't think properties are the appropriate level to specify
namespace based access modifiers. I do think that a coarse-grained
access restriction on a class by class basis might be.
public class Foo {} // Default
private class Foo {}
(protected is meaningless because there is no inheritance for
namespaces.)
In principle, I like the idea of adding an access modifier for classes
to distinguish between a namespace's public interface and its private
features.
But, when do you check for access violations of class names? On use?
On new? What about esoteric things like reflection and the callback
pseudo-type? I just don't see how it could work in practice.
Best Regards,
Jeff
Since everyone is in the "namespace" frame of mind, is there a
possibility of a "namespace" access modifier?The way I envision this working is that if for example:
namespace Foo;
class Bar {
nsprotected $_someProperty = null;
}(or some other equivalent grammer)
Would allow the property Foo::Bar::$_someProperty to be accessed
from any class that has implemented a class from the Foo namespace.Reaching for straws or is this a possibility?
-ralph
Jeff Moore wrote:
I don't think properties are the appropriate level to specify namespace
based access modifiers. I do think that a coarse-grained access
restriction on a class by class basis might be.
Perhaps you are right, but I was using that as an example. I actually
see great value in being able to declare a specific method inside a
calls of a component/namespace as namespace-protected. Alot of times
you see that objects within a given component might do something like:
class Foo_Bar
{
protected $_someProperty = null;
public function _setSomeProperty($value)
{
$this->_someProperty = $value
}
}
as a means to describe that an object of type Foo_Baz can interact with
Foo_Bar, but Foo_Bar::_setSomeProperty() should not be considered a safe
method to be called by a developer from an API standpoint.
Wouldn't that be nice?
pseudo-type? I just don't see how it could work in practice.
Wouldn't it work the same way as protected methods work? Essentially,
protected methods ensure that the caller is in the inheritance (is_a)
chain. This would simple add a new check (for methods marked
nsprotected) to check to ensure that the caller is a derivative of a
specific namespace.
-ralph