Re: [PHP] Updating inherited attributes without __construct()
On Fri, Jun 6, 2008 at 2:09 PM, Tyson Vanover <[EMAIL PROTECTED]> wrote: > Sorry, I probably should have included the add() function from the parent. > As well as all of the parent constructor. > > Basically the object takes an array of key=>value pairs and parses them > into a string for output. When it takes in the array of pairs it needs to > check the keys against a list of valid keys. I have no preference on how to > store the list of valid keys other than to add more a constructor doesn't > need to be called. > > class parent{ > $validkeys = 'name,size'; > $attributes = array(); > > __construct($set){ >foreach($set as $key=>$value){ > if(isValidKey($key)){ >$this->attributes[$key] = $value; > } >} > } > > __toString(){ >$output = ""; >foreach($this->attributes as $key=>value){ > $output .= sprintf(TEMPLATE, $key, $value); >} > } > > __set($key, $value){ >if(isValidKey($key)){ > $this->attributes[$key] = $value; >} > } > > isValidKey($key){ > ...Something goes here... > } > } > > class child extends parent{ > ...All this needs to do is tack on values 'color,shape' to parent's valid > keys... > } > > class grandchild extends child{ > ...All this needs to do is tack on values 'cost,location' to child's valid > keys... > } > > Most sub classes won't need anything different from their parent but the > expanded list of valid keys. perhaps instead of subclassing you could write a set of decorators, with a base decorator, that the others extend. something like this, class BaseParentDecorator { protected $additionalValidKeys = array(); protected $theParent = null; public function __construct($parent) { $this->theParent = $parent; } public function __toString() { return $this->theParent->__toString(); } public function __set($key, $value) { $this->theParent->$key = $value; } public function isKeyValid($key) { /// determine if key is valid, by looking at $this->validKeys /// put that boolean result in a variable, like $isKeyValid, then return $isKeyValid || $this->theParent->isKeyValid($key); } } and now, instead of subclassing parent, to a potentially deep hierarchy, all your new classes will subclass BaseParentDecorator, so working off your example from above, we would have something like, class child extends BaseParentDecorator { protected $validKeys = array(/* tacked on values for child */); } class grandchild extends BaseParentDecorator { protected $validKeys = array(/* tacked on values for grandchild */); } then at runtime you simply wrap a child instance by the grandchild instance, as in $thing = new grandchild(new child(new parent(array(/* stuff */))); -nathan
Re: [PHP] WSDL/SOAP/PHP5
On Fri, Jun 6, 2008 at 6:33 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Fri, Jun 6, 2008 at 2:53 PM, Dan Joseph <[EMAIL PROTECTED]> wrote: > >> Hi Everyone, >> >> I'm struggling with a WSDL trying to make it work right. I don't even know >> what to really ask. >> >> Basically I've created a WSDL and made a web service in PHP5. It doesn't >> seem to validate properly when a .NET client tries to hit > > > have you tried hitting it w/ soapUi ? thats a great tool for development. > > Is there something that can be used to generate the WSDL? > > > there are some things, but they are all independent projects, heres one for > example, > http://www.jool.nl/new/index.php?file_id=1 > > if you just google around a while for things like "php wsdl generator" you > can find some. i found something that looked good a few weeks back, but > having no immediate need for it, ive not used it, and dont recall where to > find it =/ > > >> Should I just abandon PHP5's SOAP and use NuSOAP? > > > obviously nusoap will be slower, but ive found the integrated php soap stuff > to be a little lean on the feature side. for example, when someone was > trying to work w/ soap attachments recently (client side issue [obviously]) > it appears there is no such support in the c code. i did find some xml in > the .phpt files that had the attachments, but there were no unit tests that > used them. > > i found some stuff in one of the soap packages in pear that did handle soap > attachments, but again, this code is php, not c. to summarize, the > integrated support for soap in php is great because its fast and you dont > have to do anything but include it in the php installation to use it. the > lacking features can be a bit painful tho. SoapClient is great, but server > side, if i ever have a need in my personal stuff for soap web services, ill > probly use java as its way more mature in this arena (and fast :D). > > -nathan > nusoap was really simple to get the attachments working correctly. Perhaps it might not have been as proper with namespace support and all that mess, but who cares if you can get at your data and it works. I saw the PEAR SOAP client did have support but I didn't see any way whatsoever to get it to work correctly. I'm sure I could have asked on the list, but really it should have been documented somewhere. Other than that, what Nathan said. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] WSDL/SOAP/PHP5
On Fri, Jun 6, 2008 at 2:53 PM, Dan Joseph <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > I'm struggling with a WSDL trying to make it work right. I don't even know > what to really ask. > > Basically I've created a WSDL and made a web service in PHP5. It doesn't > seem to validate properly when a .NET client tries to hit have you tried hitting it w/ soapUi ? thats a great tool for development. Is there something that can be used to generate the WSDL? there are some things, but they are all independent projects, heres one for example, http://www.jool.nl/new/index.php?file_id=1 if you just google around a while for things like "php wsdl generator" you can find some. i found something that looked good a few weeks back, but having no immediate need for it, ive not used it, and dont recall where to find it =/ > Should I just abandon PHP5's SOAP and use NuSOAP? obviously nusoap will be slower, but ive found the integrated php soap stuff to be a little lean on the feature side. for example, when someone was trying to work w/ soap attachments recently (client side issue [obviously]) it appears there is no such support in the c code. i did find some xml in the .phpt files that had the attachments, but there were no unit tests that used them. i found some stuff in one of the soap packages in pear that did handle soap attachments, but again, this code is php, not c. to summarize, the integrated support for soap in php is great because its fast and you dont have to do anything but include it in the php installation to use it. the lacking features can be a bit painful tho. SoapClient is great, but server side, if i ever have a need in my personal stuff for soap web services, ill probly use java as its way more mature in this arena (and fast :D). -nathan
[PHP] WSDL/SOAP/PHP5
Hi Everyone, I'm struggling with a WSDL trying to make it work right. I don't even know what to really ask. Basically I've created a WSDL and made a web service in PHP5. It doesn't seem to validate properly when a .NET client tries to hit Is there something that can be used to generate the WSDL? Should I just abandon PHP5's SOAP and use NuSOAP? -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."
[PHP] Re: Sr. PHP Engineer job opportunity / Denver
Hello, > I have an immediate opportunity available for a Senior Software Engineer in > Denver, CO (relocation assistance is available). This is a great opportunity > to join a dynamic and growing Internet-based company. The individual will > be responsible for the development, implementation, and maintenance of our > scalable, reusable, web/software based user interfaces. You must be familiar > with design patterns and be able to write abstract classes that adhere to > standard OOP methodologies. The qualified candidate will expand our > web-based platform, building new features and products. You may want to take a look at this directory of PHP professionals available for taking PHP jobs in the United States. You may even narrow your search professionals that have the skills you need: http://www.phpclasses.org/professionals/country/us/ -- Regards, Manuel Lemos PHP professionals looking for PHP jobs http://www.phpclasses.org/professionals/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Updating inherited attributes without __construct()
Sorry, I probably should have included the add() function from the parent. As well as all of the parent constructor. Basically the object takes an array of key=>value pairs and parses them into a string for output. When it takes in the array of pairs it needs to check the keys against a list of valid keys. I have no preference on how to store the list of valid keys other than to add more a constructor doesn't need to be called. class parent{ $validkeys = 'name,size'; $attributes = array(); __construct($set){ foreach($set as $key=>$value){ if(isValidKey($key)){ $this->attributes[$key] = $value; } } } __toString(){ $output = ""; foreach($this->attributes as $key=>value){ $output .= sprintf(TEMPLATE, $key, $value); } } __set($key, $value){ if(isValidKey($key)){ $this->attributes[$key] = $value; } } isValidKey($key){ ...Something goes here... } } class child extends parent{ ...All this needs to do is tack on values 'color,shape' to parent's valid keys... } class grandchild extends child{ ...All this needs to do is tack on values 'cost,location' to child's valid keys... } Most sub classes won't need anything different from their parent but the expanded list of valid keys. Nathan Nobbe wrote: i dont quite understand this reasoning.. if you want to add some valid keys, based upon the design of the parent, it seems to me the children do have a need for an overridden constructor. if you have accessor methods w/ a consistent naming convention, you could omit the $validKeys array altogether, and determine if a given field is valid based upon runtime introspection. something like this, /// in the parent class protected function isFieldValid($field) { if(method_exists($this, 'get' . ucfirst($field))) return true; else return false; } this will work in all the child classes as well, as long as you stick to a consistent naming convention, and you can of course add a check for a set.. method as well if you like. im not saying this technique is the holy grail or anything, im merely offering it as an alternative to your current solution. -nathan > On Thu, Jun 5, 2008 at 12:15 PM, Tyson Vanover <[EMAIL PROTECTED]> wrote: > >> I have a class that has a list of valid keys, and an array of values. When >> a value is added to the array it's key is first checked against the list of >> valid keys (this is to prevent injection issues we have been having later on >> in the project). >> >> class parent{ >>private $validkeys = 'title,color,name'; >>private $values = array(); >> } >> That class is inherited by other classes that mostly just have an expanded >> list of valid keys. I would like to be able to update the valid key list >> without having to craft a constructor for child objects. I would rather not >> give each child class the constructor, >> >> __construct() >> { >>$this->validkeys.= ',setting,...'; >>parent::__construct(); >> } >> >> since most child classes have no need of a unique constructor. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] spaces - not sure if this is a preg_match issue or a regexp issue
DeadTOm wrote: I'm working on a script to look for a UUEncoded attachment in an NNTP message. I'm running into problems with spaces in the filename of the attachment. UUEncoded files in the body of a message will start with the word "begin", then the size of the file, then the name of the file. Then the encoded file, finaly then a newline with only the word "end" like so: begin 644 photo.jpg -encoded image- end The script looks for that first line in that order so as not to confuse it with the word "begin" showing up somewhere else in the message. Here is the particular line of code that searches for that: if (preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n/m", $body)) The following seems to work for me. Is this inside a loop that you are scanning each line of the message? If not, I am guessing that it was your '^' that told the regex to match from the beginning of the string. The problem I'm running into is with spaces in the file name. For example, if it starts with this: begin 644 a_nice_photo.jpg it works just fine, decodes the image and places it below the text of the message. But if the line looks like this: begin 644 a nice photo.jpg with spaces in the filename, the script seems to stop looking after the "a", thinks this is just normal text in the message and doesn't decode the image. This results in the raw UUEncoded text showing up where the image should. I'm stumped. Any ideas? -Allen -- DeadTOm http://www.mtlaners.org [EMAIL PROTECTED] A Linux user since 1999. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Updating inherited attributes without __construct()
On Thu, Jun 5, 2008 at 12:15 PM, Tyson Vanover <[EMAIL PROTECTED]> wrote: > I have a class that has a list of valid keys, and an array of values. When > a value is added to the array it's key is first checked against the list of > valid keys (this is to prevent injection issues we have been having later on > in the project). > > class parent{ >private $validkeys = 'title,color,name'; >private $values = array(); > } > That class is inherited by other classes that mostly just have an expanded > list of valid keys. I would like to be able to update the valid key list > without having to craft a constructor for child objects. I would rather not > give each child class the constructor, > > __construct() > { >$this->validkeys.= ',setting,...'; >parent::__construct(); > } > > since most child classes have no need of a unique constructor. i dont quite understand this reasoning.. if you want to add some valid keys, based upon the design of the parent, it seems to me the children do have a need for an overridden constructor. if you have accessor methods w/ a consistent naming convention, you could omit the $validKeys array altogether, and determine if a given field is valid based upon runtime introspection. something like this, /// in the parent class protected function isFieldValid($field) { if(method_exists($this, 'get' . ucfirst($field))) return true; else return false; } this will work in all the child classes as well, as long as you stick to a consistent naming convention, and you can of course add a check for a set.. method as well if you like. im not saying this technique is the holy grail or anything, im merely offering it as an alternative to your current solution. -nathan
Re: [PHP] Array of PDO objects
2008/6/6 Miguel J. Jiménez <[EMAIL PROTECTED]>: > Hi, I want to know if I can set an array with PDO objects, thus: > >$foo = array(new PDO(...), new PDO(...)); >$oSt = $foo[0]->prepare(...); > > and so on... I tried that aproach and PHP is always complaining about > using prepare() in a non-object... i doubt it has anything to do w/ PDO. have you tried var_dump() to inspect the contents of $foo[0] ? and also, have you tried creating the PDO instances w/ the same arguments outside of the array construct to determine if there is any difference? -nathan
[PHP] spaces - not sure if this is a preg_match issue or a regexp issue
I'm working on a script to look for a UUEncoded attachment in an NNTP message. I'm running into problems with spaces in the filename of the attachment. UUEncoded files in the body of a message will start with the word "begin", then the size of the file, then the name of the file. Then the encoded file, finaly then a newline with only the word "end" like so: begin 644 photo.jpg -encoded image- end The script looks for that first line in that order so as not to confuse it with the word "begin" showing up somewhere else in the message. Here is the particular line of code that searches for that: if (preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n/m", $body)) The problem I'm running into is with spaces in the file name. For example, if it starts with this: begin 644 a_nice_photo.jpg it works just fine, decodes the image and places it below the text of the message. But if the line looks like this: begin 644 a nice photo.jpg with spaces in the filename, the script seems to stop looking after the "a", thinks this is just normal text in the message and doesn't decode the image. This results in the raw UUEncoded text showing up where the image should. I'm stumped. Any ideas? -Allen -- DeadTOm http://www.mtlaners.org [EMAIL PROTECTED] A Linux user since 1999. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Method chaining off constructors
On Fri, 2008-06-06 at 11:35 -0400, Christoph Boget wrote: > > The 'new' keyword has to apply to the object created in the constructor (and > > not the return value of any of the follow-up calls.) To establish this > > precedence, chaining wasn't allowed on constructors. > > If precedence was the issue, why doesn't this work, either: > > (new bob())->one()->two() > > ? Or, rather, why couldn't that have been taken into consideration? It seems a bit futile asking on PHP General when this a question for the PHP Internals list. That is where these kinds of decisions are made. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Method chaining off constructors
> The 'new' keyword has to apply to the object created in the constructor (and > not the return value of any of the follow-up calls.) To establish this > precedence, chaining wasn't allowed on constructors. If precedence was the issue, why doesn't this work, either: (new bob())->one()->two() ? Or, rather, why couldn't that have been taken into consideration? thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Method chaining off constructors
The 'new' keyword has to apply to the object created in the constructor (and not the return value of any of the follow-up calls.) To establish this precedence, chaining wasn't allowed on constructors. On Fri, Jun 6, 2008 at 11:04 AM, Eric Butera <[EMAIL PROTECTED]> wrote: > On Fri, Jun 6, 2008 at 11:00 AM, Christoph Boget <[EMAIL PROTECTED]> > wrote: > >> > Why? I thought constructors returned the object? > >> It's been a while since I've played with objects in PHP, but couldn't > >> you just add the line: > >> return $this; > >> ...to the end of your __construct() function? Sorry if this is obtuse of > >> me to say, I just thought maybe the answer was that simple and you're > >> like I am--you've been staring at a tree for so long, racking your > >> brain, that you forget about the forest altogether. :) > > > > The constructor should already be returning $this. > > > > thnx, > > Christoph > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > If you want to do this you need to define a function/method that > returns an instance for you. So you can say > > class bob { > > public static function getInstance() { > return new bob(); > } > > public function foo() { > } > > } > > bob::getInstance()->foo(); > > I've seen on the internals list where core dev's said it doesn't make > sense to chain off a constructor. If you want this behavior then you > need to do it off a method. This is just how things work is all it > boils down to. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Method chaining off constructors
On Fri, Jun 6, 2008 at 11:00 AM, Christoph Boget <[EMAIL PROTECTED]> wrote: >> > Why? I thought constructors returned the object? >> It's been a while since I've played with objects in PHP, but couldn't >> you just add the line: >> return $this; >> ...to the end of your __construct() function? Sorry if this is obtuse of >> me to say, I just thought maybe the answer was that simple and you're >> like I am--you've been staring at a tree for so long, racking your >> brain, that you forget about the forest altogether. :) > > The constructor should already be returning $this. > > thnx, > Christoph > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > If you want to do this you need to define a function/method that returns an instance for you. So you can say class bob { public static function getInstance() { return new bob(); } public function foo() { } } bob::getInstance()->foo(); I've seen on the internals list where core dev's said it doesn't make sense to chain off a constructor. If you want this behavior then you need to do it off a method. This is just how things work is all it boils down to. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Method chaining off constructors
> > Why? I thought constructors returned the object? > It's been a while since I've played with objects in PHP, but couldn't > you just add the line: > return $this; > ...to the end of your __construct() function? Sorry if this is obtuse of > me to say, I just thought maybe the answer was that simple and you're > like I am--you've been staring at a tree for so long, racking your > brain, that you forget about the forest altogether. :) The constructor should already be returning $this. thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Method chaining off constructors
> -Original Message- > From: Christoph Boget [mailto:[EMAIL PROTECTED] > Sent: Friday, June 06, 2008 9:45 AM > To: PHP General > Subject: [PHP] Method chaining off constructors > > Is there a reason why you can't do method chaining off of constructors? > > Consider the following class: > > class bob > { > public function __construct() > { > echo 'Constructor()'; > } > > public function one() > { > echo '->one()'; > return $this; > } > > public function two() > { > echo '->two()'; > return $this; > } > } > > This works: > > $bob = new bob(); > $bob->one()->two(); > > whereas this doesn't. > > $bob = new bob()->one()->two(); > > Why? I thought constructors returned the object? It's been a while since I've played with objects in PHP, but couldn't you just add the line: return $this; ...to the end of your __construct() function? Sorry if this is obtuse of me to say, I just thought maybe the answer was that simple and you're like I am--you've been staring at a tree for so long, racking your brain, that you forget about the forest altogether. :) Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Method chaining off constructors
Is there a reason why you can't do method chaining off of constructors? Consider the following class: class bob { public function __construct() { echo 'Constructor()'; } public function one() { echo '->one()'; return $this; } public function two() { echo '->two()'; return $this; } } This works: $bob = new bob(); $bob->one()->two(); whereas this doesn't. $bob = new bob()->one()->two(); Why? I thought constructors returned the object? thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array of PDO objects
Hi, I want to know if I can set an array with PDO objects, thus: $foo = array(new PDO(...), new PDO(...)); $oSt = $foo[0]->prepare(...); and so on... I tried that aproach and PHP is always complaining about using prepare() in a non-object... --- .-. | Miguel J. Jiménez | | Sector Público, ISOTROL S.A.| | [EMAIL PROTECTED] | :-: | KeyID 0xFFE63EC6 hkp://pgp.rediris.es:11371 | :-: | Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.| | Parque Tecnológico Cartuja '93, 41092 Sevilla (ESP).| | Tlfn: +34 955 036 800 (ext.1805) - Fax: +34 955 036 849 | | http://www.isotrol.com | :-: | UTM ED-50 X:765205.09 Y:4144614.91 Huso: 29 | :-: | "Me dijeron: 'instala Windows, se listo'; así que | | instalé primero Windows y luego fui listo y lo borré| | para instalar Linux"| '-' signature.asc Description: PGP signature