php-general Digest 30 Oct 2011 12:47:33 -0000 Issue 7545
php-general Digest 30 Oct 2011 12:47:33 - Issue 7545 Topics (messages 315545 through 315550): PHP syntax - novice question 315545 by: Phil Dobbin 315546 by: Simon J Welsh 315547 by: Phil Dobbin Re: create file after form completion 315548 by: Tommy Pham Re: What is an information_id in directory 315549 by: Lester Caine Array has `trailing comma`, why not the same for function parameter list? 315550 by: Nam Gi VU Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Hi, all. I’m new to the list PHP in general have a syntax question. I have a script that calls both DB MDB2. This is the part of the script where the error occurs: if($type == DB) { $db = DB::connect($dsn); if (PEAR::isError($db)) { die($db-getMessage()); } $db-setFetchMode(DB_FETCHMODE_ASSOC); $res = $db-query( 'SELECT * FROM users'); if (PEAR::isError($res)) { die($res-getMessage()); } echo ‘pre’; while( $res-fetchInto( $row ) ) { print_R($row); } echo ‘/pre’; } else if($type == MDB2) { $mdb2 = MDB2::connect($dsn); if (PEAR::isError($mdb2)) { die($mdb2-getMessage()); } $res = $mdb2-query( 'SELECT * FROM users'); // Always check that result is not an error if (PEAR::isError($res)) { die($res-getMessage()); } echo ‘pre’; while ($row = $res-fetchRow(MDB2_FETCHMODE_ASSOC)) { print_R($row); } echo ‘/pre’; } ### The syntax checker calls the first instance ofecho ‘pre’; saying unexpected I’m at a loss to understand why... I’m using PHP 5.3.8 PEAR 1.9.4 with MySQL 5.1.59 on Mac OS X 10.6.8. Any help appreciated. Cheers, Phil. -- Please consider the environment before reading this email... ---End Message--- ---BeginMessage--- On 30/10/2011, at 1:15 PM, Phil Dobbin wrote: Hi, all. I’m new to the list PHP in general have a syntax question. I have a script that calls both DB MDB2. This is the part of the script where the error occurs: if($type == DB) { $db = DB::connect($dsn); if (PEAR::isError($db)) { die($db-getMessage()); } $db-setFetchMode(DB_FETCHMODE_ASSOC); $res = $db-query( 'SELECT * FROM users'); if (PEAR::isError($res)) { die($res-getMessage()); } echo ‘pre’; while( $res-fetchInto( $row ) ) { print_R($row); } echo ‘/pre’; } else if($type == MDB2) { $mdb2 = MDB2::connect($dsn); if (PEAR::isError($mdb2)) { die($mdb2-getMessage()); } $res = $mdb2-query( 'SELECT * FROM users'); // Always check that result is not an error if (PEAR::isError($res)) { die($res-getMessage()); } echo ‘pre’; while ($row = $res-fetchRow(MDB2_FETCHMODE_ASSOC)) { print_R($row); } echo ‘/pre’; } ### The syntax checker calls the first instance ofecho ‘pre’; saying unexpected I’m at a loss to understand why... I’m using PHP 5.3.8 PEAR 1.9.4 with MySQL 5.1.59 on Mac OS X 10.6.8. Any help appreciated. Cheers, Phil. It seems as though your editor has changed the normal quotes around pre into pretty quotes. Change the ‘s and ’s back to '. --- Simon Welsh Admin of http://simon.geek.nz/ ---End Message--- ---BeginMessage--- On 30/10/11 at 01:18, si...@welsh.co.nz (Simon J Welsh) wrote: It seems as though your editor has changed the normal quotes around pre into pretty quotes. Change the ‘s and ’s back to '. Hi, Simon. Thanks for that. Couldn’t see for looking... Cheers, Phil. -- Please consider the environment before reading this email... ---End Message--- ---BeginMessage--- This line is consider 'top post'. Meaning you're posting on top of the reply. On Sat, Oct 29, 2011 at 12:12 PM, Pau vim.u...@googlemail.com wrote: Hi, Please try not to top post. sorry, but I do not understand the expression (I am not native, as you might have guessed). Do you mean not to include the email in my reply? Sorry about that. Where as this line is bottom posting. Meaning you'd be posting bottom/below the reply, which is the preferred method on this list. Regards, Tommy ---End Message--- ---BeginMessage--- Ernie Kemp wrote: 2 - Make a new
Re: FW: [PHP] What is an information_id in directory
Ernie Kemp wrote: 2 - Make a new content area in Site Manager-Content Manager. It doesn't matter what you put in your content area, you could just put This is my new content area or Hello World if you so choose. 3 - Grab the information_id of the new content area you made. When you are editing a content area that already exists, the information_id can be gotten from the update page URL. I'm having trouble understanding this request: 1. In item #2 the client wishes to put content here, I can only guess he means a file with text in it. ? 2. Item #3 I know what an ID is but not in this context. I'm don't understand what the client wishes here.?? Assuming that this is a site that is powered by a database, then one would be creating a new record in the database to store the content in rather than a new file, although one could get away with a list of files. The problem is you need to identify the next 'file/content' number, and that needs the 'information_id'. Using a database, there would be a unique index on the 'information_id' field, and you would just look up in the database to see if a number exists and pull the data from that record. Creating a new page just grabs the next 'information_id' number. One could get away by looking for the 'biggest' file number, but I suspect that 'Site Manager-Content Manager' already has some of the infrastructure to manage this? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array has `trailing comma`, why not the same for function parameter list?
It is convenient to have a trailing comma when defining an array - so as easy to add/remove code to add/remove an entry to the array array( 'key00' = 'value00', 'key01' = 'value01', 'key02' = 'value02', ... ) I suggest to PHP Development team to make it available in the syntax to have a leading comma array( ... , 'key00' = 'value00' , 'key01' = 'value01' , 'key02' = 'value02' ) in such way, we can thought of the leading commas as the list bulletings. And the same things would be lovely to be applied also to function parameter list. I don't see why not :) What do you thing about my suggestion? Hope to hear from you! -- Nam
[PHP] Dependency Injection Implementation
Hi everyone, Dependency Injection is a very trendy subject and after reading about it I kinda thought about rewriting the framework I'm doing with dependency injection. So I made my own implementation and was wondering what would you think about it? I have followed the article of Martin Fowler ( http://martinfowler.com/articles/injection.html) with this implementation I have the following : - you have both constructor and setter injection - the Dependency class is a service locator - we have at the same time service locator AND dependency injection - you can always manually inject dependency - you can pass arguments to the injected object constructor So: am I missing something? Do you think it's good enough? here is the code : ?php class Dependency { protected $_singletonInstances = array(); protected $_setInstances = array(); protected $_configuration; public static function getInstance() { static $instance = NULL; if (NULL === $instance) { $instance = new static(); } return $instance; } public function setConfiguration(array $configuration) { $this-_configuration = $configuration; } public function getConfiguration() { return $this-_configuration; } public function __isset($serviceName) { return isset($this-_serviceInstances[$serviceName]); } public function __call($serviceName, $args) { // singleton if (isset($this-_configuration[$serviceName]) $this-_configuration[$serviceName]['singleton']) { if (!isset($this-_singletonInstances[$serviceName])) { $rc = new \ReflectionClass($this-_configuration[$serviceName]['class']); $this-_singletonInstances[$serviceName] = empty($args) ? $rc-newInstance() : $rc-newInstanceArgs($args); } $ret = $this-_singletonInstances[$serviceName]; } else { // normal if (isset($this-_setInstances[$serviceName])) { $ret = $this-_setInstances[$serviceName]; unset($this-_setInstances[$serviceName]); } else { $rc = new \ReflectionClass($this-_configuration[$serviceName]['class']); $ret = $this-_singletonInstances[$serviceName] = empty($args) ? $rc-newInstance() : $rc-newInstanceArgs($args); } } return $ret; } public function __get($serviceName) { return $this-__call($serviceName, array()); } public function __set($serviceName, $instance) { if (!is_object($instance)) throw new Exception('instance must be an object'); $this-_setInstances[$serviceName] = $instance; } } class DependencyInjectorException extends \Exception { } $di=DependencyInjector::getInstance(); $di-setConfiguration(array( 'database.connector'=array( 'singleton'=true, 'class'='DatabaseConnector' ), 'database'=array( 'singleton'=true, 'class'='Database' ) )); class DatabaseConnector{} class Database{ protected $_connector; public function __construct(){ $this-setConnector(DependencyInjector::getInstance()-{'database.connector'}); } public function setConnector($connector){ $this-_connector=$connector; } } class Test{ protected $_database; public function __construct(){ $this-setDatabase(DependencyInjector::getInstance()-database); } public function setDatabase($db){ $this-_database=$db; } public function getDatabase(){ return $this-_database; } } $test=new Test(); var_dump($test-getDatabase()); ?
[PHP] Novice question
Hi I'm afraid I've fallen a little out of touch with PHP dev, so a stupid question for you. I want to write a script that requests a URL and then reads that website .. I'm interested to map web structures. My web host is saying I'll need URL file access enabled but that it's a) a security risk and b) deprecated. So .. what's the good / proper / acceptable / secure way of reading in URLs in PHP or .. isn't there one? Cheers J -- 01723 376477 Cost-free marketing: http://www.flowmarketing.co.uk/ Affordable marketing guidance for small businesses: http://www.amilliontweaks.co.uk/ Effective marketing services for SMEs: coming soon at http://www.surgemarketing.co.uk Professional Internet marketing consultancy: http://www.johnallsopp.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Novice question
Your question is NOT Novice and I really want to know the answer like you. On 10/30/11, John Allsopp j...@johnallsopp.co.uk wrote: Hi I'm afraid I've fallen a little out of touch with PHP dev, so a stupid question for you. I want to write a script that requests a URL and then reads that website .. I'm interested to map web structures. My web host is saying I'll need URL file access enabled but that it's a) a security risk and b) deprecated. So .. what's the good / proper / acceptable / secure way of reading in URLs in PHP or .. isn't there one? Cheers J -- 01723 376477 Cost-free marketing: http://www.flowmarketing.co.uk/ Affordable marketing guidance for small businesses: http://www.amilliontweaks.co.uk/ Effective marketing services for SMEs: coming soon at http://www.surgemarketing.co.uk Professional Internet marketing consultancy: http://www.johnallsopp.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Novice question
I want to write a script that requests a URL and then reads that website .. I'm interested to map web structures. My web host is saying I'll need URL file access enabled but that it's a) a security risk and b) deprecated. simplehtmldom is pretty great for this, if I understand your needs correctly... also not sure about it's server setting requirements, but worth a look.. http://simplehtmldom.sourceforge.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Novice question
On 2011-10-30, at 2:45 PM, Marc Guay marc.g...@gmail.com wrote: I want to write a script that requests a URL and then reads that website .. I'm interested to map web structures. My web host is saying I'll need URL file access enabled but that it's a) a security risk and b) deprecated. simplehtmldom is pretty great for this, if I understand your needs correctly... also not sure about it's server setting requirements, but worth a look.. http://simplehtmldom.sourceforge.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another option is cURL www.php.net/curl Bastien Koert 905-904-0334 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Zend Amf and Drupal?
Silence ? I havn't got any responses from drupal.org, and i think its very quiet here too? Should I start to analyze the code to understand the inner workings? Can anyone give some advise on where to get more information? Or... is there another proven way to communicate between Flash and PHP/Drupal? Regards Lars Nielsen lør, 29 10 2011 kl. 12:53 +0200, skrev Lars Nielsen: Hey List, I am making a webservice in Drupal with AMF Zend to provide some methods to a Flash app. I have now managed to use standard Drupal services (node,user and files) and I have made my own method to create users. But! ... When I try to pass on arguments from Flash to Drupal it fails. It says that it expects zero arguments but I have provided 4 arguments. I have posted some info here : http://drupal.org/node/1323678 Can you give me some guidelines? or pointers on what to do? Kind Regards Lars Nielsen www.lfweb.dk / www.gearworks.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] function.session-start in Webmaster Tools
Hello all. Not sure just how much of this is PHP related, but hoping someone has come across this before. I Google's webmaster tools for a site I work on, they list more than 100 crawl errors for pages with URL's as follows: http://mydomain.com/My-Directory/function.session-start Can anyone explain why webmaster tools is seeing pages with links ending in function.session-start? I read up on the error itself... sometimes caused by whitespace before the session_start tag... have fixed that. Any info is appreciated. --Rick
Re: [PHP] Novice question
On Sun, 30 Oct 2011 17:24:07 - John Allsopp j...@johnallsopp.co.uk wrote: Hi I'm afraid I've fallen a little out of touch with PHP dev, so a stupid question for you. I want to write a script that requests a URL and then reads that website .. I'm interested to map web structures. My web host is saying I'll need URL file access enabled but that it's a) a security risk and b) deprecated. So .. what's the good / proper / acceptable / secure way of reading in URLs in PHP or .. isn't there one? cURL is the best one in my experience, but you have to manage security yourself. Meaning: Remember to escape/encode data. http://php.net/manual/en/book.curl.php Cheers J -- 01723 376477 Cost-free marketing: http://www.flowmarketing.co.uk/ Affordable marketing guidance for small businesses: http://www.amilliontweaks.co.uk/ Effective marketing services for SMEs: coming soon at http://www.surgemarketing.co.uk Professional Internet marketing consultancy: http://www.johnallsopp.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function.session-start in Webmaster Tools
On Sun, Oct 30, 2011 at 4:30 PM, Rick Dwyer rpdw...@earthlink.net wrote: Hello all. Not sure just how much of this is PHP related, but hoping someone has come across this before. I Google's webmaster tools for a site I work on, they list more than 100 crawl errors for pages with URL's as follows: http://mydomain.com/My-Directory/function.session-start Can anyone explain why webmaster tools is seeing pages with links ending in function.session-start? I read up on the error itself... sometimes caused by whitespace before the session_start tag... have fixed that. Any info is appreciated. Off the top of my head, check to make sure your robots.txt is in order, see http://www.robotstxt.org/robotstxt.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array has `trailing comma`, why not the same for function parameter list?
On Sun, Oct 30, 2011 at 8:47 AM, Nam Gi VU nam.gi...@gmail.com wrote: It is convenient to have a trailing comma when defining an array - so as easy to add/remove code to add/remove an entry to the array array( 'key00' = 'value00', 'key01' = 'value01', 'key02' = 'value02', ... ) I suggest to PHP Development team to make it available in the syntax to have a leading comma array( ... , 'key00' = 'value00' , 'key01' = 'value01' , 'key02' = 'value02' ) in such way, we can thought of the leading commas as the list bulletings. And the same things would be lovely to be applied also to function parameter list. I don't see why not :) What do you thing about my suggestion? Hope to hear from you! WRT functions: while I could see how this would seem like a good idea because of the symmetry in what's going on at a very high level of abstraction, I would be against including it in a language. I don't particularly like it for arrays, but it does make it easy to add items into an array, which happens pretty often in development, especially when writing exploratory code. Function signatures, on the other hand, probably aren't changing nearly as often. At the very least, I wouldn't want to encourage people to make functions with many parameters, as it's normally a sign of poor design. This wouldn't explicitly do so, but would do so implicitly as it's only real purpose is to make it easier to add things. As far as the supporting-a-leading-comma thing goes, I'm pretty ambivalent on it. I don't really like the style outside of Haskell code, but that's just a preference. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php