PHP own functions autocomplete from included files in Dreamweaver CS5 - php

I'm using Dreamweaver CS5. I know that code hinting works in Dreamweaver with own functions/classes, but only if the functions file is included one level from main script.
Here an example:
main_script.php
include(my_functions.php)
this work and all functions which included in my_functions.php will hint when I'm editing the main_script.php (strg + space).
Other example:
main_script.php (own functions not available)
include(global_config.php) (own functions available)
include(my_functions.php) (own functions available)
Do you know if there is some trick or fix in other versions of Dreamweaver? If code hinting would work with several included levels that would make work much easier.
I've searched this site and several others but didn't find anybody with nearly the same problem, maybe somebody here can help.

Thankyou for the Editors you suggest me. I just tried out the PHPStorm and this Support codeHinting with several included files in a Project automaticly.
I just found out that Dreamweaver CS5 also Support this, in a bit other way here is a good tutorial Video for this:
http://tv.adobe.com/de/watch/lerne-dreamweaver-cs5/code-hinting-und-phphilfestellungen/
You can config a custome code hinting under "Site" => "SiteSpecific CodeHints"
Better then nothing ;)
Tom

Not sure if it works in dreamweaver but you could try adding a phpdoc eg:
include('global_config.php');
/* #var $functions Functions */
$functions = new Functions();
This assumes your functions are wrapped in a class

Related

Use PHP code in .TPL files in Kohana/Smarty Framework

I am unable to write PHP code in .tpl file in either ways
I tried <?php echo 'test'; ?>
I also tried {PHP} echo 'test'; {/PHP}
But both returned error
on line 14 "{php}echo "hello!"{/php}" unknown tag "php"
I've not worked with Kohana, but with Smarty 3, use of the php tag is deprecated. You'll need to use the backwards compatibility mode with 3.0. It is highly recommended that all code logic be placed in your controller or php script files, and not your Smarty templates.
If you want to use PHP code in templates, it is suggested you create custom functions or modifiers.
So, basically, the short answer is find where your code (or the Kohana plugin) is instantiating Smarty and change it to use SmartyBC, but be aware that this is highly discouraged.
If you are using Kohana Smarty3 module for Kohana, these code lines should help set you in the right direction.

Saving OOP PHP files as .class

Quick question. Is it okay to save a PHP class file as myClass.class and include it in other "regular" .php files?
It works just fine in PHP 5.3, but I'm wondering if it is bad practice.
tl;dr:
useObjects.php
<? include('myClass.class');
$my_object_1 = new myClass();
?>
myClass.class
<?
//constructors and functions
?>
Thank you!
EDIT: This is just for my own organization.
The only technical reason not to do this is if the web server is not configured to parse .class files as PHP scripts, and if a file is beneath the document root and accessed via the browser, it will display PHP source code to the end user exposing source code or sensitive data like database connection details.
Beyond that, it's a matter of convention. And while PHP doesn't have too many conventions to speak of, .class is a pretty unusual one. *.class.php is fairly common, however.
It's unusual, since .class is not necessarily a common PHP convention, but other than that there's no technical reason against it.
Since the only thing that really matters is PSR-0. You should name classes so it works with that standard.
\Doctrine\Common\IsolatedClassLoader = Doctrine/Common/IsolatedClassLoader.php
\Symfony\Core\Request = Symfony/Core/Request.php
\Zend\Acl = Zend/Acl.php
\Zend\Mail\Message = Zend/Mail/Message.php
Nothing wrong with using it but. Conventionally i would prefer to use .inc with means include.

PHP function descriptions as I type in Notepad++

Is there a plugin for Notepad++ which would allow me to see functions including parameters/returns as I type?
For example, if i type "implode(", I'd see:
string implode ( string $glue , array $pieces )
Update: Wow, I'm surprised so many other people were as interested in this as me. The take-home lesson for me was to always explore all the Settings options!
You don't need a plugin! 5.0 and above have this already.
Go to Settings -> Preferences, then go to the Backup/Auto-Completion tab, and you'll find it at the bottom! Check the box for function parameters hint as well.
You'll get exactly what you've asked for, as long as it knows the file is PHP.
maybe, plugin Auto completion for custom PHP classes (ACCPC) is what you're mean.
basic info:
Show an overview over your classes' attributes & methods in a nice popup!
A popup window appears after typing the "->" or "::" behind a class or an instantiated object variable which displays all attributes and methods of it's class.
more information:
http://sourceforge.net/projects/accpc/
maybe this answer can helpful too:
Get parameter hints from Editing the API XML file
https://stackoverflow.com/a/12609240/2427906
You can read about it in Notepad++'s documentation site found here
http://npp-community.tuxfamily.org/
The auto complete section can be found here
http://npp-community.tuxfamily.org/documentation/notepad-user-manual//editing/auto-completion

Any way to subvert class redeclaration issue? No namespaces

Heads up: I dont have the possibility to rename the classes or use name spaces for this.
Im looking for any crazy way to subvert class redeclaration issues in php. I actually only need 3 static variables from a web application, but the only way to get them requires including a file that declares a user class. However I already have a user class, so I get an error.
I tried to no avail to include the file in a class hoping it would isolate the included file - But no.
I tried reading an interface file I created that just echos the 3 values, but that actually just reads the php code and not the rendered values.
Is there anything like an opto-isolation system for code?
The only think I can think of is using ajax to do it, but it seems super sketchy. Is there a plain php version of this?
(Was a comment, but got too long.) Doesn't sound doable with your constraints. (You might need to show some code.) -- But if you are asking for a crazy way, and the option to rename the classes just applies to not editing the php script, then:
Load the include file into a variable, then transform it, and finally eval:
$source = file_get_contents("user.php");
$source = str_replace("class user", "class workaround_123", $source);
eval($source); // will give you a workaround_user instead of class conflict
Someone will probably comment on the advisability of eval... But it foremost depends on your code/situation if that's an applicable wacky workaround.
Alternatively you could invoke the user fetching code with a separate PHP process :
exec("QUERY_STRING=user=123 php-cgi user.php");
You could tokenize the whole file and go through it "by hand" to find the values you need.

custom php function creation and install

I would like to know how to create a php function that can be installed in php
just like the already built in functions like :
rename
copy
The main point I would like to achieve is a simple php function that can be called from ANY php page on the whole host without needing to have a php function within the php page / needing an include.
so simply I would like to create a function that will work like this :
location();
That without a given input string will output the current location of the file via echo etc
Well, there are a couple of options here. One of them is to actually extend the language by writing an extension. You'd have to muck around with the PHP source code, write it in C, and deal with the Zend Engine internally. You probably wouldn't be able to use this on a shared host and it would be quite time consuming and probably not worth it.
What I would do is put all of your functions into a separate PHP file, say helper_functions.php. Now, go into your php.ini and add the directive: auto_prepend_file = helper_functions.php. This file should be in one of the directories specified in your include_path (that's a php.ini directive too).
What this does is basically automatically put include 'helper_functions.php'; on every script. Each and every request will have these functions included, and you can use them globally.
Read more about auto_append_file.
As others have said, there's probably an easier, better way to do most things. But if you want to write an extension, try these links:
http://docstore.mik.ua/orelly/webprog/php/ch14_01.htm
http://www.tuxradar.com/practicalphp/2/3/0
So you want to extend PHP's core language to create a function called location(), written in C, which could be done in PHP by:
echo __FILE__;
Right. Have fun doing that.

Categories