[PHP] General question: packaging in PHP

2005-01-30 Thread Vivian Steller
Hello,
i've a general question concerning PHP's architecture.

Why isn't there a native packaging concept in PHP?

I think php became much more powerfull with the extended OOP features
introduced in PHP5 - without a packaging concept you couldn't use these
features in big business (in terms of sharing classes/libraries). I know
the discussion of OOP features vs. PHPs scripting capabilities, but IMHO
doing the half way of OOP isn't right...

Are there any thoughts about that in future releases?
What do other developers think about this issue?
How do organize multiple used classnames?

Thanks for your answers..
with best regards,

vivian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] General question: packaging in PHP

2005-01-30 Thread Vivian Steller
verffentlicht  per Mail versendet

Thanks for your answer!

Terje Sletteb wrote:

From: Vivian Steller [EMAIL PROTECTED]
 
 i've a general question concerning PHP's architecture.

 Why isn't there a native packaging concept in PHP?
 
 This was also suggested on comp.lang.php, recently (the nested class
 thread), called namespaces, but there wasn't a lot of enthusiasm for it.
 Apparently, it was even implemented at one point, but then subsequently
 dropped. I've found it difficult to find the relevant discussion in the
 archive (possible the internals-list or Zend's engin2-list), could anyone
 provide a link?
 
 I think php became much more powerfull with the extended OOP features
 introduced in PHP5 - without a packaging concept you couldn't use these
 features in big business (in terms of sharing classes/libraries). I
 know the discussion of OOP features vs. PHPs scripting capabilities, but
 IMHO doing the half way of OOP isn't right...
 
 I guess package/namespace doesn't have a lot to do with OO (except that
 they both allow grouping of functionality, and avoiding name collision,
 but that's not the only benefit of OO), but as there hasn't been any
 enthusiasm for overloading, either (not even for user-defined types, where
 you _can_ use type hints in function signatures), and it's common in OO
 languages, I guess you have a point. 
Thanks for metioning this issue! This is another point where I think OO is
done the half way in PHP:

Why do we need some implicit type check, like
public method(Type $type)
if we then loose the optional parameter advantage?

Either some polymorphism mechanism should be implemented, or something like
public method(Type $type = new MyType())
should be able being passed through the interpreter..

also the primitive datatypes should be (exceptionally) used here:
public method(string $argument)

Otherwise (IMHO) the typecheck mechanism is useless.

 Interestingly, I found that Perl has 
 the possibility of function overloading (also a language that's
 dynamically typed)
 (http://www.math.tu-berlin.de/polymake/perl/overload.html) It also has -
 like Python - operator overloading. But is there any enthusiasm for that
 in the PHP community, either? Nah...
regrettably... :(

 
 Are there any thoughts about that in future releases?
 What do other developers think about this issue?
 How do organize multiple used classnames?
 
 The common answer is: Use a prefix...
but i really dislike using cryptic and long prefixes to ensure uniqueness...
dots in the classname (ok, doing it like java) would be so nice, gr**

 
 Regards,
 
 Terje

vivian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: ext/dom: Namespaces

2004-03-14 Thread Vivian Steller
hello,

once again a post about the tricky namespaces. I played with the following
functions concerning namespaces:

domdocument-createElementNS
domdocument-createAttributeNS
domelement-setAttributeNS
domelement-getAttributeNS
(domelement-hasAttributeNS)

as i found out the behavior of some functions differs when handling
namespaces. maybe we can start a thread thinking about this behavior - at
the moment i don't have the enlightened view into this very complex
theme. would be nice if you could help me/us understanding namespaces a bit
more...

ok here are the things i found out. copy the code to your editor and step
through the examples - the important output is given in the comments.
Thanks for taking time to that :)

/* START */
pre

/* SIMPLE NAMESPACE EXAMPLE */
?php
$doc = new DomDocument();
$xpath = new DomXPath($doc);

/* SIMPLE NAMESPACE EXAMPLE */
$node1 = $doc-createElementNS(namespaceURI, nodeName);
$node1 = $doc-appendChild($node1);

print(htmlspecialchars(\n . $doc-saveXML() . \n));
// Output
//  nodeName xmlns=namespaceURI/

$namespaces = $xpath-query(//namespace::*);
foreach($namespaces as $item) {
print($item-nodeName .  =  . $item-nodeValue . \n);
}
// Output
//  xmlns:xml = http://www.w3.org/XML/1998/namespace
//  xmlns = namespaceURI
$doc-removeChild($node1);
?

Right behavior so far!



/* NAMESPACE WITH PREFIX EXAMPLE */
?php   
/* NAMESPACE WITH PREFIX EXAMPLE */
$node2 = $doc-createElementNS(namespaceURI, prefix:localName);
$node2 = $doc-appendChild($node2);

print(htmlspecialchars(\n . $doc-saveXML() . \n));
// Output
//  prefix:localName xmlns:prefix=namespaceURI/

$namespaces = $xpath-query(//namespace::*);
foreach($namespaces as $item) {
print($item-nodeName .  =  . $item-nodeValue . \n);
}
// Output
//  xmlns:xml = http://www.w3.org/XML/1998/namespace
//  xmlns:prefix = namespaceURI

// $doc-removeChild($node2);
?

Still right behavior!



/* NAMESPACE WITH EXISTING PREFIX EXAMPLE */
?php
/* NAMESPACE WITH EXISTING PREFIX EXAMPLE */
$node3 = $doc-createElementNS(namespaceURI, localName);
$node3 = $node2-appendChild($node3);

print(htmlspecialchars(\n . $doc-saveXML() . \n));
// Output
//  prefix:localName xmlns:prefix=namespaceURI ¬
//  prefix:localName/ ¬
//   /prefix:localName

$namespaces = $xpath-query(//namespace::*);
foreach($namespaces as $item) {
print($item-nodeName .  =  . $item-nodeValue . \n);
}
// Output
//  xmlns:xml = http://www.w3.org/XML/1998/namespace   (node2)
//  xmlns:prefix = namespaceURI   
 (node2)
//  xmlns:xml = http://www.w3.org/XML/1998/namespace   (node3)
//  xmlns:prefix = namespaceURI   
 (node3)

// $doc-removeChild($node3);
?

Right behavior, but namespace node will be removed, xpath-expression shows
prefix - thats still right. 



/* IMPORT NAMESPACE NODE WITHOUT CHILDREN EXAMPLE */
?php
/* IMPORT NAMESPACE NODE WITHOUT CHILDREN EXAMPLE */
$newDoc = new DomDocument();
$newXpath = new DomXPath($newDoc);

$newNode3 = $newDoc-importNode($node3);// second argument $deep = 
FALSE!!
$newNode3 = $newDoc-appendChild($newNode3);

print(htmlspecialchars(\n . $newDoc-saveXML() . \n));
// Output
//  localName/

$newNamespaces = $newXpath-query(//namespace::*);
foreach($newNamespaces as $item) {
print($item-nodeName .  =  . $item-nodeValue . \n);
}
// Output
//  xmlns:xml = http://www.w3.org/XML/1998/namespace   (newNode3)

$newDoc-removeChild($newNode3);
?

Maybe right behavior, but i think loosing the namespace while importing the 
node without its children is a bit dangerous...



/* IMPORT NAMESPACE NODE EXAMPLE */
?php
/* IMPORT NAMESPACE NODE EXAMPLE */ 
$newNode3 = $newDoc-importNode($node3, TRUE);  // second argument $deep =
TRUE now!!
$newNode3 = $newDoc-appendChild($newNode3);

print(htmlspecialchars(\n . $newDoc-saveXML() . \n));
// Output
//  prefix:localName xmlns:prefix=namespaceURI/

$newNamespaces = $newXpath-query(//namespace::*);
foreach($newNamespaces as $item) {
print($item-nodeName .  =  . $item-nodeValue . \n);
}
// Output
//  xmlns:xml = http://www.w3.org/XML/1998/namespace   (newNode3)
//  

[PHP] PHP5: Segmentation Fault in ext/dom

2004-03-04 Thread Vivian Steller
Hello,

i know that this post should better been sent to bugs.php but making my
first experiences on segmentation faults i can't identify the right causes
to report it... have a look and help me getting right informations to post
the bug so that it can be solved.

Error type:
'''
error_log sais segmentation fault sometimes; while running the script the
server (not all the time!) starts a proc with 50-90% of users processor
resources?!

Source:
'''
Using todays snapshot php5-200403041230.tar.gz

Concerning extensions:
''
- ext/dom: XPath query function
(- maybe referencing behavior of variables in general??)

Code:
'
[The code is VERY BIG... here is just a snippet causing the error]

?php
...
// $xpath is a DomXPath Object
// $filesystem holds a wellformed expression string
if(is_string($this-filesystem)) {
$this-filesystem = $xpath-query($this-filesystem);
}
// $this-filesystem should store a DomNodeList
// and sometimes it does!!
...
?


This code (i think) works fine:
?php
...
// $xpath is a DomXPath Object
// $filesystem holds a wellformed expression string
if(is_string($this-filesystem)) {
$nodeList = $xpath-query($this-filesystem);
}
// $nodeList should store a DomNodeList
...
?
 
Problem description:

Other tests in my script showed that the problem occurs if I try to store in
an $object-var.


Maybe you need some more informations to fix this problem?
Comments are appreciated!

Thanks in advance,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php5

2004-03-03 Thread Vivian Steller
hi again,
i forgot adding the attributes, sorry :)
here it is...

 I need manipulate the nodes (add and remove) .
 example
 I need add more one node
 interface name=dmz type=ethernet device=eth3 ip=xxx
 subnet=24/
 
 ?php
 // create a new node
 $newInterfaceNode = $doc-createElement(interface);
 // append this node under network
 $newInterfaceNode = $networkNode-appendChild($newInterfaceNode);
 ?

?php
$newInterfaceNode-setAttribute(name, dmz);
$newInterfaceNode-setAttribute(type, ethernet);
$newInterfaceNode-setAttribute(device, eth3);
$newInterfaceNode-setAttribute(ip, x);
?

the setAttribute method only works for appended nodes...

you can get a peace of technical documentation of the used methods from 
http://www.eecoo.de/downloads/domdocumentation.txt .

i'm happy being able to help you, maybe you'll help us later on;)

bye.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: check if a variable is declared as private

2004-03-02 Thread Vivian Steller
Hello,

is it possible to check if a variable declared as private?
I do not want to use reflection api in this case...

?php
class MyClass {
private $var = something;
}

$obj = new MyClass();

// something like this would be nice...
$isPrivate = isPrivate($obj, var);
?

best regards,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: check if a variable is declared as private

2004-03-02 Thread Vivian Steller
Jakes wrote:

 The word private says it all - If you create a object,
 you are not going to be able to use it, because its
 private to that class. Its a class variable, not a object variable
 

oh, yeah - your right of course... taking a look at get_object_vars($obj)
output doesn't show private variables (i expected other behavior) - thats
fine.

thanks anyway
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: static class variables

2004-03-02 Thread Vivian Steller
hello again,

once again a question about class properties, this time more reasonable...

Is there a possibility to check wether a static variable is set or not?

?php
class MyClass {
public static $var;
}

print_r(get_class_vars(MyClass));
?

will not show $var, cause it's static.

an expression like

if(MyClass::$somevar) {...}

ends up to a fatal error because $somevar is not declared.
is there a function to check if $somevar is declared?

unfortunately reflection api is VERY buggy yet...

thanks in advance,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php5

2004-03-02 Thread Vivian Steller
Carlos wrote:

 hello ... I'm working with simplexml (php5) to manipulate the data in
 xml file, but I'm having one problem.

i'm not familiar with simplexml but with the dom functions and i think (as
simplexml is based on dom) the simplexml objects will work with dom objects
as well?!
otherwise you'll perhaps get an idea how to work with extended DOM
functions :)

See below:

put your xml into a variable $xml..
 ?xml version=1.0?
leaving the first line out...
so $xml=
 config
 network defaultroute= dnsserver=
 interface name=lan type=ethernet device=eth0
 ip=192.168.1.1 subnet=24/
 interface name=wan type=ethernet device=eth1
 ip=192.168.1.1 subnet=24/
 alias number=1 desc=teste device=eth0/
 alias number=2 desc=teste1 device=eth1/
 /network
 /config
;

?php
$doc = new DomDocument();
$doc-loadXML($xml);// this will parse your code into dom

// xpath will help to get the right nodes
$xpath = new DomXPath($doc);

$networkNode = $xpath-query(/config/network)-item(0);
?

 I need manipulate the nodes (add and remove) .
 example
 I need add more one node
 interface name=dmz type=ethernet device=eth3 ip=xxx
 subnet=24/

?php
// create a new node
$newInterfaceNode = $doc-createElement(interface);
// append this node under network
$newInterfaceNode = $networkNode-appendChild($newInterfaceNode);
?

 and remove the node
 
 alias number=2 desc=teste1 device=eth1/

?php
// xpath again
$aliasNode = $xpath-query(//[EMAIL PROTECTED] = '2'])-item(0);
// remove the node (don't no exactly if this works...)
$aliasNode-parentNode-removeChild($aliasNode);
?
 
 but I don't have idea ...
 somebody can help me ?
 Any example ...
 
 greats
 
 Carlos

have fun :)

regards,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: Class behavior: method overloading

2004-02-26 Thread Vivian Steller
Hello,

in the latest snapshot i found some very important differences to the php5
beta 4 version concerning the behavior of inherited classes. please look at
the following example:

pre
?php
class MyClass extends MyParent{ 
function test($arg) {

}
}   

class MyParent {
function test($arg1, $arg2) {

}
}

$obj = new MyClass();
?
/pre

the output is:

Fatal error:  Declaration of MyClass::test() must be compatible with that of
MyParent::test() in ... on line 3


I think that this is a nice feature in the face of compatibility, but may
cause in a complete restructure of existing class trees. The consequence is
a bad :( backward compatibility!! Personally I think it would be a good
solution to set an option in the configuration or something like this.

other oppinions would be appreciated.

thanks,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DEV] PHP5: Class behavior: method overloading

2004-02-26 Thread Vivian Steller
Walter A. Boring IV wrote:

 I say keep compatibility.  If you want to enforce this, then declare an
 interface.  That is after all why they exist.
 
 Walt
...

Would be nice if you could give a simple example - i really have problems
working with interfaces :(

My problem was to design a filesystem structure with classes like this:

class Folder {
var $name;
var $path;

function init() {}  // should set $name and $path...

function read($recursive = FALSE) {}// should read own content and
eventually all subdirs
}

class File extends Folder {
// inherited properties and funcs...

function read() {}  // should read the file content, $recursive is not
needed

}


how could i implement my interfaces? I think interfaces wouldn't solve php4
compatibility problems...

best regards,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: Directory DirectoryIterator

2004-02-25 Thread Vivian Steller
Hello,

using PHP5 Beta 4 I saw some new classes like DirectoryIterator with nice
methods like:

__construct
rewind
hasMore
key
current
next
getPath
getFilename
getPathname
getPerms
getInode
...

but i don't know how to apply them?
Would be nice if somebody could post some links with code examples
(recursive filesystem reading; just getting folder contents; etc.)...

Thanks,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP5: Directory DirectoryIterator

2004-02-25 Thread Vivian Steller
Ben Ramsey wrote:

 using PHP5 Beta 4 I saw some new classes like DirectoryIterator with nice
 methods like:
 
 
 Where did you see these classes?  Is it a PEAR package?  I haven't seen
 these in the PHP manual.
 

You can find them using the following function:

function printDeclaredClasses() {
$classes = get_declared_classes();
foreach($classes as $class) {
print(\nb . $class . /b\n);
$methods = get_class_methods($class);
foreach($methods as $method) {
print(\t . $method . \n);
}
}
}

make a printDeclaredClasses(), search for DirectoryIterator and you can
see available methods for that class..

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Global vars or Environment var on Class

2004-02-17 Thread Vivian Steller
Turbo wrote:

 Hi
 
 I cann't call Global vars or Environment var on Class.How to's i do to
 call it?
 I want to call variable same below.
 
 var $location
 =http://.$HTTP_SERVER_VARS['HTTP_HOST'].$_SERVER['REQUEST_URI'].?
$HTTP_SERVER_VARS['QUERY_STRING'];
 
 
 Thank you.
 Turbo.

i would try the following:
- check if it works with $GLOBLAS['_SERVER']['REQUEST_URI']..., but I think
your implementation should work then, too.
- so: if you don't necessarily need this var to be a real class var (with
the only disadvantage not seeing it when asking for
get_class_vars(Class)) then let the var set by the constructor:

?php
class Foo {
var $location = ;

function Foo() {
$this-location = $GLOBLAS['_SERVER']['REQUEST_URI'] . ...;
}
}
?

hope i could help.
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: ext/dom: Namespace Prefix unexpected behavior

2004-02-17 Thread Vivian Steller
Hello,
checking out the behavior of Namespaces  Prefixes of the new dom
implementation of PHP5 I got some (for me!) unexpected results.

look at the following source code: (plz copypaste it to your editor ;)

pre
?php
// PHP5: ext/dom: Namespace Tests

function printRootNS($xmlCode) {
$doc = new DomDocument();

$doc-loadXML($xmlCode);
$root = $doc-documentElement;
print(trim(htmlspecialchars($doc-saveXML())) . \n\t = Namespace of
root-Element: b . $root-namespaceURI . /b\n\n); 
}

function printRootNSNewPrefix($xmlCode, $newPrefix) {
$doc = new DomDocument();

$doc-loadXML($xmlCode);
$root = $doc-documentElement;
$root-prefix = $newPrefix;
print(trim(htmlspecialchars($doc-saveXML())) . \n\t = Namespace of
root-Element: b . $root-namespaceURI . /b\n\n); 
}

printRootNS('prefix:root xmlns:prefix=somedomain.name
xmlns:anotherprefix=anotherdomain.name/');

print(\nI'm going to change prefix with \\$root-prefix =
'anotherprefix';\ now... \n\n\n);
printRootNSNewPrefix('prefix:root xmlns:prefix=somedomain.name
xmlns:anotherprefix=anotherdomain.name/', anotherprefix);
?
/pre


This is the corresponding output:

?xml version=1.0?
prefix:root xmlns:prefix=somedomain.name
xmlns:anotherprefix=anotherdomain.name/
 = Namespace of root-Element: somedomain.name


I'm going to change prefix with $root-prefix = 'anotherprefix'; now... 


?xml version=1.0?
xml:root xmlns:prefix=somedomain.name
xmlns:anotherprefix=anotherdomain.name/
 = Namespace of root-Element: http://www.w3.org/XML/1998/namespace



I thought that setting $root-prefix will set the prefix and the
namespaceUri to the other domain... but it seems to me that the parser
doesn't see the xmlns:anotherprefix as a prefix-declaration?
maybe i just misunderstood something, so please correct me if so.

I know, namespaces are quite difficult to implement - it isn't my goal to
annoye you with it!

Best regards,
vivian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-XML-DEV] Re: [PHP] PHP5: ext/dom - set namespace of node manually

2004-02-17 Thread Vivian Steller
Rob Richards wrote:

 From: Christian Stocker
 
  $node-setAttributeNS(http://www.w3.org/2000/xmlns/;, xmlns:b,
  http://www.somedomain.de/;);
 
 
 IMHO, that would be very confusing.

 I liked the idea by vivian with a third optional namespaceURI argument
 for the element object, so that at least you can use your own extended
 classes for that.

 And maybe we still need a -setNamespaceURI method, even if W3C didnt
 think of that ;)
 
 After thinking about it some more I started to think about it the same
 way. One can always then use $node-prefix = xyz to set the prefix (if
 needed) for the initial namespace delcaration.
 It probably has to wait until 5.1 though since its so close to the
 release.
 
 Rob

first of all, thanks for your interests...
i tried my self in extending your code - i'm really no C programmer, just
copypasted it (poor to say that, sorry:), but it seems to work.

i now can use the following syntax to set the namespaceUri of a node:

?php
$element = new DomElement(tagname, value, http://namespaceUri;);
// or
$element = new DomElement(pref:tagname, value, http://namespaceUri;);
// works as well
?

here is the diff output:

--- ./element_original.c2004-02-15 15:08:52.0 +0100
+++ ./element.c 2004-02-17 20:53:35.0 +0100
@@ -64,11 +64,14 @@
 
zval *id;
xmlNodePtr nodep = NULL, oldnode = NULL;
+   xmlNsPtr nsptr = NULL;
dom_object *intern;
-   char *name, *value = NULL;
-   int name_len, value_len = 0;
+   char *name, *value = NULL, *uri = NULL;
+   char *localname = NULL, *prefix = NULL;
+   int name_len, value_len = 0, uri_len = 0;
+   int errorcode;
 
-   if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
Os|s, id, dom_element_class_entry, name, name_len, value, value_len)
== FAILURE) {
+   if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
Os|ss, id, dom_element_class_entry, name, name_len, value,
value_len, uri, uri_len) == FAILURE) {
return;
}
 
@@ -77,15 +80,49 @@
RETURN_FALSE;
}
 
-   nodep = xmlNewNode(NULL, (xmlChar *) name);
+   //
+
+   errorcode = dom_check_qname(name, localname, prefix, uri_len, name_len);
+
+   if (errorcode == 0) {
+   nodep = xmlNewNode(NULL, (xmlChar *) localname);
+
+   if (!nodep)
+   RETURN_FALSE;
+
+   if (value_len  0) {
+   xmlNodeSetContentLen(nodep, value, value_len);
+   }
+   // nodep = xmlNewDocNode (docp, NULL, localname, NULL);
+   if (nodep != NULL  uri != NULL) {
+   nsptr = xmlSearchNsByHref (nodep-doc, nodep, uri);
+   if (nsptr == NULL) {
+   nsptr = dom_get_ns(nodep, uri, errorcode, prefix);
+   }
+   xmlSetNs(nodep, nsptr);
+   }
+   }
 
-   if (!nodep)
+   xmlFree(localname);
+   if (prefix != NULL) {
+   xmlFree(prefix);
+   }
+
+   if (errorcode != 0) {
+   if (nodep != NULL) {
+   xmlFreeNode(nodep);
+   }
+   php_dom_throw_error(errorcode, dom_get_strict_error(intern-document)
TSRMLS_CC);
RETURN_FALSE;
+   }
 
-   if (value_len  0) {
-   xmlNodeSetContentLen(nodep, value, value_len);
+   if (nodep == NULL) {
+   RETURN_FALSE;
}
 
+
+   nodep-ns = nsptr;
+   //
intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
if (intern != NULL) {
oldnode = (xmlNodePtr)intern-ptr;
@@ -97,8 +134,8 @@
 }
 /* }}} end dom_element_element */
 
-/* {{{ proto tagName   string  
-readonly=yes 
+/* {{{ proto tagName   string
+readonly=yes
 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226
DOM3-Core.html#core-ID-104682815
 Since: 
 */


as you said it's close to the release and i won't bring you into trouble,
but maybe you can take a short time to look if i had made some heavy
errors...

MANY MANY THANKS in advance,
best regards

vivian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-XML-DEV] Re: [PHP] PHP5: ext/dom - set namespace of node manually

2004-02-16 Thread Vivian Steller
Christian Stocker wrote:

 ...
 Vivian, it's not possible the set the namespace according to the W3C
 standard, except with createElementNS(). As Adam said, in PHP 4, there
 was the option set_namespace, which isn't ported to PHP5 (yet).
 
 Maybe we should port that function as well, to allow some deeper level
 manipulation of the namespaces...
 
 Currently, I don't have a solution to your problem, except porting
 setNamespace to PHP5...
 
 chregu
 

Porting the setNamespace function to PHP5 would be nice. Another solution
could be the possibility to append a namespace-node (is the
domnamespacenode class currently used by any functions?) or the
setAttribute checks wether some xmlns/xmlns: attribute is set and
updates namespaceUri itself... would be more W3C standard compliant.

without the functionality to set the namespace it will never be possible to
overwrite the createElementNS of domdocument, as the following example
shows:

?
class MyElement extends DomElement {...}

class MyDocument extends DomDocument {
function createElement($name, ...) {
$element = new MyElement($name, ...);
return $element;
}

function createElementNS($uri, $name, ...) {
$element = new MyElement();
// here you should set the Namespace...
// ...unfortunatly impossible

// that would be nice
$element-setNamespace(http://...;);
// - maybe you get into trouble with NO MODIFICATION ALLOWED 
ERROR!!
//because node isn't appended

// or something like
$element-setAttributeNS(http://www.w3c.org/2000/xmlns;, 
xmlns,
http://mydomain.de/;);
// - maybe you get into trouble with NO MODIFICATION ALLOWED 
ERROR!!
//because node isn't appended

return $element;
}
}
?

i think because of the problems with the MODIFICATION ERRORS while node
isn't appended, it would be best if you could define the node-namespace
with the third argument of DomElement::__construct($name, $value, $uri =
defaultUri)...

it would be VERY nice if you think about such solutions...

thanks a lot,
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: ext/dom - set namespace of node manually

2004-02-15 Thread Vivian Steller
Hello,
the following code shows my problem:

?php
class MyElement extends DomElement {
function __construct($name) {
parent::__construct($name);
}
}

$doc = new DomDocument();

$node = new MyElement(test);
$node = $doc-appendChild($node);
$node-setAttribute(xmlns, http://www.somedomain.de/;);

print(Namespace: ' . $node-namespaceURI . ');

$xmlCode = $doc-saveXML();
print(pre . htmlspecialchars($xmlCode) . /pre);
?

the output would be:
 Namespace: ''
 ?xml version=1.0?
 test xmlns=http://www.somedomain.de//

As you can see it is impossible to set the namespace manually! I tried to
set it with the help of a DomNamespaceNode-object but those objects are no
real nodes (why!?!) and the consequence is that you couldn't append such
a node with $node-appendChild($domnamspacenode_object); ...

Further it isn't possible to use the function $doc-createElementNS(...)
because this function returns a domelement-object but i want the element to
be my own MyElement-object.

So how to get a namespace in my node???

thanks in advance,

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php5: read-only variables

2004-02-09 Thread Vivian Steller
hello,

talking about php5, i'm missing read-only attributes/variables for
classes/objects. i.e. this would be very useful for implementing the new
DOM Level 3 Interfaces as given in http://www.w3.org/TR/2003
CR-DOM-Level-3-Core-20031107/idl-definitions.html .

And I don't think of any reason for Zend-Developers not to implement a
little keyword readonly... particularly they're using it in there C-Code
as you can see by testing the following script:

?php
$doc = new DomDocument();

$root = new DomElement(root);
$root-tagName = test; // this, of course, doesn't work...

print($root-tagName);
$root = $doc-appendChild($root);
?

The output is a fatal error:
Fatal error: main() [function.main]: Cannot write property in ... on line 5

But i don't think they'll make any changes on it at this (beta) state?

If anybody has an acceptable fake-solution, please let me know...
thanks

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-QA] php5: read-only variables

2004-02-09 Thread Vivian Steller
Jan Lehnardt wrote:

 [...]
 * Constants.
 
 The Zend Engine 2.0 introduces per-class constants.
 
 Example:
 
 ?php
 class Foo {
 const constant = 'constant';
 }
 
 echo 'Foo::constant = ' . Foo::constant . \n;
 ?
 
 Old code that has no user-defined classes or functions
 named 'const' will run without modifications.
 
 [...]

thanks, but i think constants are not the same as readonly variables!!
a constant - as the name sais - are values that should never be changed. but
in my example 

?php
$doc = new DomDocument();

$root = new DomElement(root);
$root-tagName = test; // this, of course, doesn't work...

print($root-tagName);
$root = $doc-appendChild($root);
?

the constructor (/another class-) function of DomElement has to set the
object variable $root-tagName to root, of course. this is why tagName
isn't defined as constant...
further you CAN read $root-tagName, but not set it - so it is a real
READONLY variable, define in C-Code of Zend Engine...

anyway, thanks a lot...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] getting classname of current class

2004-02-06 Thread Vivian Steller
Hi,

i've just another problem concerning classes, inheritance and the '::'
Syntax. Take a look at the following example code:

pre
?php
class MyClass extends MyParent{
private $__arr = Array();

public function __construct() {
$this-__arr(test);
}

public function __arr($var) {
array_push($this-__arr, $var);
}
}   

class MyParent {
public function getClassname() {
print(My classname:  . __class__ . \n);
print(My classname:  . get_class($this) . \n);
}
}

$obj = new MyClass();
// print_r($obj);

MyClass::getClassname();
?
/pre

Corresponding output:

 My classname: MyParent
 My classname: 


The problem is, that i want MyClass::getClassname() to return MyClass?!

Can anybody help me?

Thanks a lot.
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: class variables problem / array_push bug

2004-02-05 Thread Vivian Steller
hi at all,

i've a very strange problem but i don't know if this a real bug or only my
imcompetence?!

it is a problem with class variables set by __constructor() function in
PHP5...
look at this code:

?
   class MyClass extends DomNode {  // remove extends DomNode and
everything is fine
  private $__arr = Array();

  public function __construct() {
 //$this-__arr = Array();  // uncomment this line for testing
 $this-__setVar(value set inside constructor);
  }

  public function __setVar($classname) {
 print(\n\nexecuting __setVar()\n);
 print(trying to push \ . $classname . \ into \$this-__arr
with array_push\n);
 // array_push only works in several cases...
 array_push($this-__arr, $classname);

 // comment following line for testing
 //$this-__arr[] = $classname; 

 /*
 foreach($this-__arr as $parentClassname) {
print($parentClassname . \n);
 }
 */
  }
   }

   print(pre);
   $node = new MyClass();
   print_r($node);
   $node-__setVar(value set outside object method);
   print_r($node);
   print(/pre);
?

output:
***
executing __setVar()
trying to push value set inside constructor into $this-__arr with
array_push
MyClass Object
(
[__arr:private] = Array
(
)

)


executing __setVar()
trying to push value set outside object method into $this-__arr with
array_push
MyClass Object
(
[__arr:private] = Array
(
[0] = value set outside object method
)

)
***

ok, in my opinion the Array $this-_arr should have a value value set
inside constructor after creating the object set by array_push (see output
line 2)!

But there are several cases in which this bug does not appear:
- remove extends DomNode from code and it works fine
...but what does DomNode with my __construct() function?!
- uncomment line 6 and it will work
...don't ask me why it works now?!
- uncomment line 19 and it will work
...seens that array_push does not work correctly.

by the way i'm using PHP5 cvs-version from 2004-05-02 10:30...
maybe you could help me out of this dilemma..
another question for the php experts: is this information enough for sending
a bug to php.bugs?

thanks for your attention.
bye
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: __call() implementation

2004-02-05 Thread Vivian Steller
Hello,

as you know there is a new callback function __call($method, $params) in
php5. the __call() method of an object is called, if the method named
$method is not declared in this class.

i want this function simply call the method of another class with
SomeClass::$method(...) but i'm getting into trouble (bit heavy
programming!:) passing the arguments (stored as Array in $params) to the
SomeClass::$method([arguments]) method...
further, i think i'm getting problems with objects passed through the
__call() method?!

any suggestions?
thanks

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP5: __call() implementation EXAMPLE

2004-02-05 Thread Vivian Steller
Vivian Steller wrote:

 Hello,
 
 as you know there is a new callback function __call($method, $params) in
 php5. the __call() method of an object is called, if the method named
 $method is not declared in this class.
 
 i want this function simply call the method of another class with
 SomeClass::$method(...) but i'm getting into trouble (bit heavy
 programming!:) passing the arguments (stored as Array in $params) to the
 SomeClass::$method([arguments]) method...
 further, i think i'm getting problems with objects passed through the
 __call() method?!
 
 any suggestions?
 thanks
 
 vivi

ok, here is an example: hope you'll understand what i want...

pre
?php
class MyClass {
function __call($method, $params) {
// $params = Array(mixed var, mixed var, ...);
print(request for  . $method . ()\n);

// how to get objects in this string?!
// do i have to implement switch($type) { case object: ... 
} here?!
$parameterstring = \ . $params[0] . \; 
eval(OtherClass:: . $method . ( . $parameterstring . ););

}
}

class OtherClass {
function OtherMethod($obj = false) {
if(is_object($obj)) {
// this method receives an object to show the 
difficulties with object
passed through call...
if(method_exists($obj, printSomething)) {
$obj-printSomething();
}   
}
else {
print(Error: no object passed! ' . $obj . '\n);
}
}
}

class Whatever {
function printSomething() {
print(passing object through __call() is fine\n);
}
}

$someObj = new Whatever();
// $someObj-printSomething();

$MyObj = new MyClass();
// this works perfectly
$MyObj-OtherMethod(passing a string);
// this is my problem...
$MyObj-OtherMethod($someObj);
?
/pre

please, try and help :)

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP5: __call() implementation EXAMPLE

2004-02-05 Thread Vivian Steller
Vivian Steller wrote:
...
 class MyClass {
function __call($method, $params) {
   // $params = Array(mixed var, mixed var, ...);
   print(request for  . $method . ()\n);
 
   // how to get objects in this string?!
   // do i have to implement switch($type) { case
   $parameterstring = \ . $params[0] . \;
   eval(OtherClass:: . $method .
 ( . $parameterstring . ););
 
}
 }
...

ok, i'm sorry, but i found the solution for my own:

on the top you see some snippet of my EXAMPLE Message before.

you can implement the $parameterstring generation algorithm like this (and
its very very easy!!)


   $parameterstring = ;
   for($i = 0; $i  count($params); $i++) {
  if(!empty($parameterstring)) {
 $parameterstring .= , ;
  }

  $parameterstring .= \$params[ . $i . ];
   }

replace the line $parameterstring = \ . $params[0] . \; with this
code snippet and it works...

any way, thanks.

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP5: __call() implementation EXAMPLE

2004-02-05 Thread Vivian Steller
John W. Holmes wrote:

 From: Vivian Steller [EMAIL PROTECTED]
 
 Vivian Steller wrote:

...
 pre
 ?php
 class MyClass {
 function __call($method, $params) {
 // $params = Array(mixed var, mixed var, ...);
 print(request for  . $method . ()\n);

 // how to get objects in this string?!
 // do i have to implement switch($type) { case
 object: ... } here?!
 $parameterstring = \ . $params[0] . \;
 eval(OtherClass:: . $method . ( .
 $parameterstring . ););
 
 Can't you just say:
 
 OtherClass::$method($params);
 
 here?
 
...
 ---John Holmes...

No, sorry that doesn't work. Interpreter is trying to acces static member
$method .. and this member does not exist.

The error message:

Fatal error:  Access to undeclared static property:  OtherClass::$method
in ...

Thanks for your time.
vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP5: Problem concerning multiple inheritance / interfaces

2004-02-04 Thread Vivian Steller
Hello at all,
ok my problem in a nutshell: i need multiple inheritance! is there a
solution to fake this functionallity in php5?

i have the following problem:
the goal is to implement my own DomXML implementation based on the existing
DomNode, DomDocument, Dom... Classes.

thus, i implement my classes as follows:

class MyNode extends DomNode {} // that isn't the problem
class MyDocument extends DomDocument {} // would be fine, but...

this would be an easy solution,  but there is a logical problem:
if i extend the DomNode (with the methods in MyNode) then -i think-
MyDocument should have those extended methods, too.
so i could write:

class MyDocument extends MyNode {}  // problem

but now i'm missing all the nice methods of DomDocument!!
multiple inheritance would solve this problem:

class MyDocument extends MyNode,DomDocument {}  // not possible

by the way: i will get into trouble with all Dom-Classes:
class MyElement extends MyNode,DomElement {}
class MyAttribute ...

Hope you'll understand me?
Is there a way to solve this problem?
I'm thinking about the new __call() method implemented as follows:

class MyDocument extends MyNode {
function __call($method, $params) { // fake solution
...
eval(DomDocument::$method($paramsString););
}
}

but with a fake solution like this i wouldn't get all methods with
get_class_methods() and that wouldn't be that nice:)

Can Interfaces help me?

Thanks for your efforts..

vivi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php