NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Declaring object class (or variable type) in included files

 
Post new topic   Reply to topic    NetBeans Forums -> PHP Users
View previous topic :: View next topic  
Author Message
csnyder
Posted via mailing list.





PostPosted: Thu Nov 13, 2008 1:15 pm    Post subject: Declaring object class (or variable type) in included files Reply with quote

I'm wondering if there is a way to declare that some variable $foo is
an instance of class myFoo? Either globally for a project, or on a
file by file basis?

Let's say I have two php scripts, controller.php and action.php, as follows:

controller.php:
<?php
$foo = new myFoo();
$foo->load();
include( 'action.php' );
?>

action.php:
<?php
$path = 'bar';
$foo->save( $bar );
?>

Autocomplete and Go-to-declaration works on $foo in controller.php,
but not in action.php, because (presumably) there is no way for
NetBeans to determine that action.php was included by controller.php
and therefore inherits its environment.

In Zend Studio, you can use an ugly, tweaked form of @var to
specifically declare the type or class of a variable, so if action.php
is modified as follows, autocomplete etc will work, because the IDE
now knows that $foo is an instance of myFoo.

<?php
/* @var $foo myFoo */
$path = 'bar';
$foo->save( $bar );
?>

So is there an equivalent hinting method in NetBeans?

For the record, having used Zend's hack for years, I have two suggestions:

1) It would be *ideal* if you could declare a project-wide hint-sheet
for global variables, so that anytime NetBeans sees $foo in a project
file, it can assume that that is an instance of myFoo.

2) If there isn't already a way to do this, I'd suggest: @type type
variable, example @type myFoo $foo.


Chris Snyder
http://chxor.chxo.com/
Back to top
Petr Pisl
Posted via mailing list.





PostPosted: Thu Nov 13, 2008 1:42 pm    Post subject: Declaring object class (or variable type) in included files Reply with quote

Hi Snyder,

see my comments inline.
Quote:
I'm wondering if there is a way to declare that some variable $foo is
an instance of class myFoo? Either globally for a project, or on a
file by file basis?

Let's say I have two php scripts, controller.php and action.php, as follows:

controller.php:
<?php
$foo = new myFoo();
$foo->load();
include( 'action.php' );
?>

action.php:
<?php
$path = 'bar';
$foo->save( $bar );
?>

Autocomplete and Go-to-declaration works on $foo in controller.php,
but not in action.php, because (presumably) there is no way for
NetBeans to determine that action.php was included by controller.php
and therefore inherits its environment.

Unfortunately this is true. The action.php file can be included in many
files, so it can be performance problem to find all possible context for
$foo.
Quote:
In Zend Studio, you can use an ugly, tweaked form of @var to
specifically declare the type or class of a variable, so if action.php
is modified as follows, autocomplete etc will work, because the IDE
now knows that $foo is an instance of myFoo.

<?php
/* @var $foo myFoo */
$path = 'bar';
$foo->save( $bar );
?>

So is there an equivalent hinting method in NetBeans?

Unfortunately not now, but it will be implemented probably soon. You are
right that this is hack, because even according phpdoc manual the @var
tag documents the data type of class variables
(http://manual.phpdoc.org/HTMLframesConverter/default/) . I don't like
this hack, but more people want this
(http://www.netbeans.org/issues/show_bug.cgi?id=146248) we will do it.
Quote:
For the record, having used Zend's hack for years, I have two suggestions:

1) It would be *ideal* if you could declare a project-wide hint-sheet
for global variables, so that anytime NetBeans sees $foo in a project
file, it can assume that that is an instance of myFoo.

2) If there isn't already a way to do this, I'd suggest: @type type
variable, example @type myFoo $foo.



Thanks for the suggestions. Could you add them to the issue
http://www.netbeans.org/issues/show_bug.cgi?id=146248 ? I can do it by
myself, but from community member it looks better Smile.

Thanks,
Petr
Quote:
Chris Snyder
http://chxor.chxo.com/






Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> PHP Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo