|
Posted by Richard Levasseur on 08/11/06 08:26
Joseph S. wrote:
> (2)
> william.clarke wrote:
> > Sorry should have posted links:
> > PhpED: http://www.nusphere.com/products/phped.htm
> > Zend: http://www.zend.com/products/zend_studio/feature_list
> > Obviously neither of these is free, but you could try Eclipse with a Php add-on.
> I am using PHPEclipse for a long time now, (but wrote all my code in
> procedural style, not touching OOP) - but it pops up huge autocomplete
> list, and somehow, no "$this" - i'll have to look at the configuration
> - (thanks anyway)
>
The PHP plugin for eclipse is mediocre at best. I find I fight it most
of the time:
1) New lines within quoted strings: it will auto end the line and make
it concatenate, but PHP will allow returns within the line, VERY
annoying when you're writing quoted HTML attributes within a HEREDOC
block.
2) Very poor autocomplete compared to other programs. $this-> pops up
a huge list of potential matches. using built in functions will only
display the parameter list until you start the parentheses, in which
case it starts suggesting variables, which usually start with the super
globals. VERY frustrating.
3) Aggresive auto-formatting:
* Auto-inserts closing } after a { even if it is within a closed block
that it, itself, closed, creating a syntax error.
* The opening of a block with { will begin to suggest variables, and
pressing enter will auto-insert the first variable, which is usually
$_GET.
* Auto-complete of variables is iffy, too often has i tried to use
auto-complete, typed the first few characters, tab'd, and it only left
those characters instead of completing the variable name, even if it
was the only variable available.
4) Poor scope detection: it frequently suggests global variables that
aren't declared as global within the scope, thus would be inaccessible.
5) Poor auto-complete of auto-globals. Dreamweaver will display an
autocomplete for variables within $_SERVER, which is very handy. PHP
Eclipse won't.
6) No concept of current type of variable (If you've use vs.php, the
php plugin for the visual studio, you know what i mean - it can
somewhat accurately guess the type of a variable).
7) Poor help tips, see (2). You can document all your methods with
@param, @return, but you'll never see these comments from auto-complete
unless you manually hover your mouse over the method...defeating the
point of a context help as you type.
8) I could go on, but i think this is enough.
If you can get a hold of the visual studio IDE, try the vs.php plugin.
I find it vastly superior to eclipse's
> (3)
> My own personal opinion is as follows:
> if not for the "$" and the "->", PHP would have _eaten_ up a lot more
> of the market share - that it is already doing so is not surprising. It
> is simply the easiest language to work in. Lots of flexibility,
> plethora of well designed functions and a very pratical approach,
> rather than the purist apporach of Java/.Net designers which result in
> more code being required to be written to accomplish simple tasks -
> most obvious examples are file() and file_get/put_contents().
>
Why? I don't see how $ and -> has much effect on the market share.
> A Google summer of code project promises something interesting PHP
> Preprocessor Macros:
> http://code.google.com/soc/php/appinfo.html?csaid=3752FBA8CFFCD528
>
> Finally, as a practical workaround, maybe a simple global function
> could be written, say, function v($arg){
> return (eval("\$this->".variable_name($arg));
> }
> I am looking for the function variable_name(). Looked around a bit, but
> could not find one.
>
> Or better still, one could write a slightly complex parsing script, say
> code-cleaner.php, send original code to that script
> (PHP in CLI mode:)
> php -n code-cleaner.php myscript.php
>
> which will do all the substitution and overwrite myscript.php with
> "$this->" code.
> I'll try this and post it if it succeeds.
>
> One of the important things here is that PHP allows two $foo variables
> in one class:
> $foo = 5;
> class A{
> public $foo = 6;
> public function showfoo(){
> echo $foo; // 6
> echo $this->foo; // 5
> }
> }
> and that is why $this is required. I believe (please correct if wrong)
> other languages give errors like "$foo is ambiguous". I dont know as
> much of compiler internals as to know why $this-> is required
> _everywhere_.
In PHP you have to qualify class/instance variables with $this or
classname::, if it isn't, its considered a local variable, more or less
(exceptions being 'global $var' and super globals)
In most languages, there's a heirarchy of scope. In general, most
specific overrides least specific:
If we were to consider some sort of php/java/c++ hybrid:
$foo = '3';
class bar {
public $foo = '2';
function baz($foo='1';) {
$foo // local variable, 1
$this.$foo // instance, 2
$GLOBALS['foo'] // global variable, 3
}
}
in java, you can do:
class bar {
public name;
void myfunc(String name) {
name = "John"; // refers to local name
this.name = "Mary"; // refers to instance name
}
}
Most languages have that sort of heirarchy, anyways.
And in response to original poster: Just use $this->, its not that much
of a hassle.
If you dont' like typing $this-> before every var, just do $myvar = &
$this->myvar; at the start of the method.
Navigation:
[Reply to this message]
|