php-general Digest 2 May 2009 14:30:27 -0000 Issue 6099
Topics (messages 292205 through 292216):
Re: graphical integrated development environment recommendations?
292205 by: Shawn McKenzie
292210 by: Ashley Sheridan
292215 by: tedd
SOAP and Exception Handling
292206 by: VamVan
PHP6 return by reference deprecation
292207 by: Paul M Foster
292208 by: Robert Cummings
292216 by: Colin Guthrie
Re: Upload file name not file
292209 by: Ashley Sheridan
Re: object literals
292211 by: Andrea Giammarchi
292212 by: Robert Cummings
292213 by: Ashley Sheridan
292214 by: Robert Cummings
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Adam Williams wrote:
> With the wide range of users on the list, I'm sure there are plenty of
> opinions on what are good graphical IDE's and which ones to avoid. I'd
> like to get away from using notepad.exe to code with due to its
> limitations. Something that supports syntax/code highlighting and has
> browser previews would be nice features. I'm looking at Aptana
> (www.aptana.com) but it seems like it is more complicated to use then it
> should be. Either Linux or Windows IDE (i run both OSes)
> recommendations would be fine.
>
I used eclispe, but I'm using netbeans now. Runs on win and linux.
Just to edit a file here and there I use kate on linux (many text
editors have highlighting/folding on linux) and notepad++ when I have to
be on windows.
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
On Fri, 2009-05-01 at 22:09 -0400, Andrew Hucks wrote:
> http://notepad-plus.sourceforge.net/uk/site.htm
>
> Try out N++. It's very good, supports a whole bunch of languages by
> default, has folding, and you can tweak the syntax highlight if you
> want. (You don't need to though.)
>
> Takes two minutes to install, and 45 seconds to uninstall it if you
> don't like it. It's worth a try.
>
> On Fri, May 1, 2009 at 12:08 PM, Adam Williams
> <[email protected]> wrote:
> > With the wide range of users on the list, I'm sure there are plenty of
> > opinions on what are good graphical IDE's and which ones to avoid. I'd like
> > to get away from using notepad.exe to code with due to its limitations.
> > Something that supports syntax/code highlighting and has browser previews
> > would be nice features. I'm looking at Aptana (www.aptana.com) but it seems
> > like it is more complicated to use then it should be. Either Linux or
> > Windows IDE (i run both OSes) recommendations would be fine.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
I use Kate on Linux, works like N++, but has some extra features, like
built in command line console
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
At 6:06 PM -0700 5/1/09, [email protected] wrote:
Isn't phpedit windows-only?
<shudder>
Eclipse + PDT is my recommendation FWIW...
GM
<shudder> is right and it appears that they didn't get their Mac
option running by fall of 2008.
I use Eclipse for Java, but have not used it for php much. I need not
only an editor but also a file manager. Everything I've see from
Eclipse (thus far) is that you develop locally and use something else
to upload and keep track of your file remotely -- but I could be
wrong.
Thus far, I use GoLive, but sometimes that sucker craters and it's a
bitch to get everything back the way it was. It has zero tolerance
for files that might have a problem.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Hello Guys,
I use SOAP calls to make web service requests.I have a class that does
webservice calls to various wsdls. So my question is about try catch blocks.
so my method looks like this:
private function method($cookie){
//Define Client
try{
// Check if WSDL exists
if(!...@file_get_contents($this->WSDL)) {
throw new SoapFault('Server', 'No WSDL found at ' .
$this->WSDL);
}
$client = new SoapClient($this->WSDL, array(
'exceptions' => 1,
'encoding' => "UTF-8",
'connection_timeout' => 60
));
}catch(SoapFault $fault){
// Error if the WSDL is not available or new client cannot be made
//log errror
}
//Define Input Array
$input = array();
$input['cookie'] = $cookie;
//Make the call
try{
$result = $client->function($input);// Make the Call
return $result;
}catch(SoapFault $fault){
//log error
}
}
How is it possible for me to *remove *these 2 try and catch blocks from this
method and just throw exceptions, but do a try and catch in the business
logic.
So basically I might have different functions in business logic area that
might call the same method and I do error logging there itself instead
directly in the method?
Thanks,
V
--- End Message ---
--- Begin Message ---
In another thread (which I mercifully declined to highjack), someone
cited:
> Taken from http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html
And I read this:
Both '$foo =& new StdClass()' and 'function &foo' will now raise an
E_STRICT error.
I don't use this much, but where I do, it's vital. Typically, I use it
to ensure a single copy of the $config for an application, as:
function &get_config() ...
and/or:
$cfg =& get_config();
If this is going away, how do you return things by reference, so as to
ensure a single copy of something (yes, I know the singleton pattern can
be used; I do use it as well; it's more complicated)?
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-02 at 01:07 -0400, Paul M Foster wrote:
> In another thread (which I mercifully declined to highjack), someone
> cited:
>
> > Taken from http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html
>
> And I read this:
>
> Both '$foo =& new StdClass()' and 'function &foo' will now raise an
> E_STRICT error.
>
> I don't use this much, but where I do, it's vital. Typically, I use it
> to ensure a single copy of the $config for an application, as:
>
> function &get_config() ...
>
> and/or:
>
> $cfg =& get_config();
>
> If this is going away, how do you return things by reference, so as to
> ensure a single copy of something (yes, I know the singleton pattern can
> be used; I do use it as well; it's more complicated)?
PHP5 made it so that objects are always passed by handle. When assigned
or passed as a parameter a copy of the object handle is passed (rather
than a copy of the object itself a la PHP4). Given this, you are in many
ways passing around an implicit reference. It's not exactly a reference,
since there are subtle differences, but the object won't be cloned as it
is in PHP4 using this method. So singletons will work as expected. For
example:
<?php
$a = new StdClass();
$a->a = 'a';
$b = new StdClass();
$b->b = 'b';
$c = new StdClass();
$c->c = 'c';
$d = new StdClass();
$d->d = 'd';
$x = $a;
$x->x1 = 'x1';
$x = $b;
$x->x2 = 'x2';
$y = &$c;
$y->y1 = 'y1';
$y = $d;
$y->y2 = 'y2';
echo "a:\n";
print_r( $a );
echo "b:\n";
print_r( $b );
echo "c:\n";
print_r( $c );
echo "d:\n";
print_r( $d );
echo "x:\n";
print_r( $x );
echo "y:\n";
print_r( $y );
?>
You will get the following output in PHP5:
a:
stdClass Object
(
[a] => a
[x1] => x1
)
b:
stdClass Object
(
[b] => b
[x2] => x2
)
c:
stdClass Object
(
[d] => d
[y2] => y2
)
d:
stdClass Object
(
[d] => d
[y2] => y2
)
x:
stdClass Object
(
[b] => b
[x2] => x2
)
y:
stdClass Object
(
[d] => d
[y2] => y2
)
The difference between references and handles in PHP5 is exemplified
by the output of $a versus the output of $c. In the case of $c because
we assign a reference for $c to $y, then subsequently we assign $d by
value, we essentially completely replace the object $c with $d.
Whereas when we assigned $a by value to $x, then subsequently assigned
$b by value to $x only the handle value was changed.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
If this is going away, how do you return things by reference, so as to
ensure a single copy of something (yes, I know the singleton pattern can
be used; I do use it as well; it's more complicated)?
You'll want to use the Singleton design pattern here.
Let's say you're config object is a class.
Something like this should work very nicely.
class My_Config
{
private function __construct()
{
// Whatever you need to do to load the config
}
public static function getInstance()
{
static $instance = null;
if (null === $instance)
$instance = new self();
return $instance;
}
}
Then in your code whenever you want to get your config object you would
call:
$config = My_Config::getInstance();
You'll only every get one object created due to the private constructor
and which enforces the use of the getInstance() method.
This is a very common design pattern, and is ideally suited to this use
case.
HTHs
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--- End Message ---
--- Begin Message ---
On Fri, 2009-05-01 at 12:38 -0400, Simon wrote:
> On Fri, May 1, 2009 at 9:34 AM, MikeP <[email protected]> wrote:
> > I'm not trying to get the path, just the filename and size, I know how to
> > get these, but that would include the file using $_Files, but I dont want to
> > upload anything just use the filename and size.(without the path) to insert
> > into a DB.
>
> Those are attributes of the file for which you dont have access
> remotely, and the only way to access this information without an
> upload will be using the same hacks as those spywarez use. A
> technology like flash has read/write access to the remote user's disk
> (to a certain extent), you could use flash to get that information and
> make it send it to you, same thing could be done with ActiveX, etc...
> PHP, JS and HTTP protocol cannot acheive what you want. (PHP is
> server-side, HTTP is for communication only, JS is client-side but
> locked down very much).
>
> However, at a very low level, it might be possible to achieve this in
> PHP, you could do the upload as if you wanted the whole file. But the
> first packet received will contain the HTTP Header, and in the header,
> you should have all the info you need (filename and size of data).
> So, low-level speaking, as soon as you receive the first packet and
> have the info, you just need to close the connection (remote end might
> display an error msg saying the upload failed, etc). PHP supports
> sockets connections, so you could make a basic 'server' that listens
> on another port to perform this. But i see no way to acheive your
> goal without complications.
>
> Good luck!
>
If you don't set the enctype to multipart/form-data in your form, then
only the filename will be uploaded as part of the form. To get the file
size you would have to allow the file to be uploaded, even if only to
the temporary directory.
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
exactly, why bother with JavaScript literal representation?
the foreach loop was just an alternative to explicit object cast cause you did
not like it .... I though it was more about control over what you want to cast
and what you do not ... in any case, what I said does not change cause in php
you have natural type hint over arrays and these are normally slightly faster
so I do not get why you want objects rather than arrays ...
> Subject: RE: [PHP] object literals
> From: [email protected]
> To: [email protected]
> CC: [email protected]; [email protected]
> Date: Fri, 1 May 2009 12:14:21 -0400
>
> On Fri, 2009-05-01 at 17:52 +0200, Andrea Giammarchi wrote:
> > you are in PHP, not in JavaScript.
> >
> > In PHP arrays are like collections or hash tables.
> > if you strictly need object cause
> >
> > $o->stuff
> > is better than
> > $o['stuff']
> >
> > having exactly the same number of characters, you can create a
> > function like
> >
> > function o(array $a){
> > $o = new stdClass;
> > foreach($a as $key => $value)
> > $o->$key = $value;
> > return $o;
> > }
> >
> >
> > and the syntax will be
> >
> > $o = o(array(
> > 'a' => "b",
> > 'c' => "d"
> > ));
> >
> > spot the difference from (object) array(whatever) ?
> >
> > I do not ... and that's why json_encode resolves associative arrays
> > rather than list automatically but still, if you are in PHP, you
> > should think about being familiar with associative arrays, also
> > because so far is the only class you cannot create/extend.
> >
> > class string {
> > // ok
> > }
> >
> > class object {
> > // ok
> > }
> >
> > class array {
> > // no way
> > }
> >
> > Regards
>
> First off, you compared the syntax between creating a PHP array and a
> JavaScript object when the previous post specifically spoke about
> getting a PHP "OBJECT". Now you've made a rather lengthy and redundant
> post trying to describe to me objects versus arrays in PHP. Lastly
> you've suggested writing a function to convert an array to an object
> using a foreach loop for the members which is completely unnecessary.
> The following will suffice:
>
> <?php
>
> function o( array $a )
> {
> return (object)$a;
> }
>
> ?>
>
> ... and the syntax will be:
>
> <?php
>
> $o = o(array
> (
> 'a' => "b",
> 'c' => "d",
> ));
>
> ?>
>
> But why bother when you could have just done:
>
> <?php
>
> $o = (object)array
> (
> 'a' => "b",
> 'c' => "d",
> );
>
> ?>
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
_________________________________________________________________
Windows Liveā¢: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote:
> exactly, why bother with JavaScript literal representation?
>
> the foreach loop was just an alternative to explicit object cast cause you
> did not like it .... I though it was more about control over what you want to
> cast and what you do not ... in any case, what I said does not change cause
> in php you have natural type hint over arrays and these are normally slightly
> faster so I do not get why you want objects rather than arrays ...
It's not what I want, I'm not the original poster. Regardless though, it
comes down to the preference of the developer. It can certainly be
simpler to type:
$obj->blah->bleh->bluh;
than to type:
$obj['blah']['bleh']['blug'];
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-02 at 06:45 -0400, Robert Cummings wrote:
> On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote:
> > exactly, why bother with JavaScript literal representation?
> >
> > the foreach loop was just an alternative to explicit object cast cause you
> > did not like it .... I though it was more about control over what you want
> > to cast and what you do not ... in any case, what I said does not change
> > cause in php you have natural type hint over arrays and these are normally
> > slightly faster so I do not get why you want objects rather than arrays ...
>
> It's not what I want, I'm not the original poster. Regardless though, it
> comes down to the preference of the developer. It can certainly be
> simpler to type:
>
> $obj->blah->bleh->bluh;
>
> than to type:
>
> $obj['blah']['bleh']['blug'];
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>
Undefined index 'blug' in $obj on line 1 ;)
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-02 at 12:10 +0100, Ashley Sheridan wrote:
> On Sat, 2009-05-02 at 06:45 -0400, Robert Cummings wrote:
> > On Sat, 2009-05-02 at 12:39 +0200, Andrea Giammarchi wrote:
> > > exactly, why bother with JavaScript literal representation?
> > >
> > > the foreach loop was just an alternative to explicit object cast cause
> > > you did not like it .... I though it was more about control over what you
> > > want to cast and what you do not ... in any case, what I said does not
> > > change cause in php you have natural type hint over arrays and these are
> > > normally slightly faster so I do not get why you want objects rather than
> > > arrays ...
> >
> > It's not what I want, I'm not the original poster. Regardless though, it
> > comes down to the preference of the developer. It can certainly be
> > simpler to type:
> >
> > $obj->blah->bleh->bluh;
> >
> > than to type:
> >
> > $obj['blah']['bleh']['blug'];
> >
> > Cheers,
> > Rob.
> > --
> > http://www.interjinn.com
> > Application and Templating Framework for PHP
> >
> >
> Undefined index 'blug' in $obj on line 1 ;)
That is so weird... I got "Undefined variable: obj".
;)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---