Doc->Req #52029 [Opn->Asn]: create_alias namespaces
| From: | kalle@php.net | Date: | Sun, 24 Oct 2010 13:36:57 +0000 |
| Subject: | Doc->Req #52029 [Opn->Asn]: create_alias namespaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155473@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52029&edit=1
ID: 52029
Updated by: kalle@php.net
Reported by: rustyj4ck at gmail dot com
Summary: create_alias namespaces
-Status: Open
+Status: Assigned
-Type: Documentation Problem
+Type: Feature/Change Request
-Package: Documentation problem
+Package: Class/Object related
Operating System: all
PHP Version: 5.3.2
-Assigned To:
+Assigned To: dmitry
Block user comment: N
New Comment:
Moving this to a feature / change request
Previous Comments:
------------------------------------------------------------------------
[2010-06-15 12:41:49] rustyj4ck at gmail dot com
Then, where is expected functions?
is_alias()
get_alias_name()
or reflection method?
in fact we cant get alias name, aliasing is useless.
------------------------------------------------------------------------
[2010-06-15 09:48:06] dmitry@php.net
This is an expected behaviour. An alias allows to refer to a class entry
using different name but it's the same class entry.
------------------------------------------------------------------------
[2010-06-13 00:34:58] felipe@php.net
Hmm, in fact the alias is created by reusing the original class entry.
I.e. no copy is done, it just add a new entry to the class table using
the alias name pointing to the original one.
class a { }
class_alias('a', 'b');
ReflectionClass::export('b');
/*
Class [ <user> class a ] {
...
}
*/
Dmitry, are actually the aliases supposed to behave in this way?
(needing to be explained in the documentation wether it is right as is)
------------------------------------------------------------------------
[2010-06-09 13:08:28] rustyj4ck at gmail dot com
Description:
------------
Cant create alias to class in different namespace.
Created object (alias instance) return type of base class,
not alias.
Test script:
---------------
<?php
namespace tf\users {}
namespace tf\core {
class collection {
private $_cl;
function __construct() { $this->_cl = get_class($this); }
function get_cl() { return $this->_cl; }
}
class core {
private $_cl;
function register($name) {
$from = 'tf\\core\\collection';
$to = 'tf\\users\\' . $name;
printf ("aliasing %s --> %s : %s <br/> \n", $from, $to,
class_alias($from, $to)?'OK':'FAIl');
$a = new $to ();
$this->_cl = get_class($a);
return $a;
}
function get_cl() { return $this->_cl; }
}
}
namespace {
use tf\core\core;
$core = new core();
$test = $core->register('test');
printf("core: %s, result: %s, get_class: %s <br/>\n",
$core->get_cl(), $test->get_cl(), get_class($test));
}
Expected result:
----------------
tf\users\test
Actual result:
--------------
aliasing tf\core\collection --> tf\users\test : OK
core: tf\core\collection, result: tf\core\collection, get_class:
tf\core\collection
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52029&edit=1