Xu Wei Jie Posted March 24, 2009 Share Posted March 24, 2009 I wonder for PHP, are we able to set class paths so we can call a php script from a written library without specifying the full path to the script? Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/ Share on other sites More sharing options...
wildteen88 Posted March 24, 2009 Share Posted March 24, 2009 The only way you can do this is place all your classes within a dedicated folder. You'll then want to add this folder to PHP's include_path setting. So when ever you want to include a class you'd do include 'your_class.php'; rather than include 'path/to/your_class.php'; Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792854 Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 check out this: http://us.php.net/autoload Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792855 Share on other sites More sharing options...
Xu Wei Jie Posted March 24, 2009 Author Share Posted March 24, 2009 I think both of you are mistaken. I wanted to put all my written scripts into a library(folder) and set the classpath to them so I would not need to type out long paths to execute them. ( for example the php command, once it is installed and having its class path set, you can invoke it from any directory). I do want to achieve that effect. i.e php x.php x.php is stored in a library I created. i wish to invoke it from any directory, is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792885 Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 Your question has nothing to do with php itself. Its your shell that parses the command php x.php And no, x.php will need to be within the current directory or you will need to give your shell the complete path to the file. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792891 Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 What you can do however is place a shebang on the first line of your scripts. #!/usr/bin/php Then place x.php in your system path and simply execute.... x.php from your shell. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792895 Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 as thorpe said, this is OS related...not PHP. What OS is this for? Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-792950 Share on other sites More sharing options...
Xu Wei Jie Posted March 25, 2009 Author Share Posted March 25, 2009 I am currently using windows. However, I wish to be independent from platform Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-793225 Share on other sites More sharing options...
trq Posted March 25, 2009 Share Posted March 25, 2009 Your going to struggle there. Windows won't recognise a shabang and only has a very limited shell (if you could even call it that). If this is the only entry point to your application you could likey write a wrapper around it specific to the OS its running on. But again, this isn't a php question. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-793229 Share on other sites More sharing options...
rhodesa Posted March 25, 2009 Share Posted March 25, 2009 On Windows, you will need to edit the System Environmental variables to include the folder with your PHP executable as well as your 'library' Unix based platforms are the same concept, but a little different in execution edit: actually...since the path to the script would be an argument to the PHP executable, this won't work...hum.... Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-793496 Share on other sites More sharing options...
Xu Wei Jie Posted March 27, 2009 Author Share Posted March 27, 2009 Yah I guess since x.php is parsed to the php cli. It is hard to come up with a solution such that x.php can be invoked by itself and a shebang won't work with different platforms. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-795384 Share on other sites More sharing options...
Xu Wei Jie Posted March 27, 2009 Author Share Posted March 27, 2009 I found an alternative for windows. However, I don't know how a shebang works. Can anyone guide me on how to execute x.php. This script is not on a server. x.php #!C:\php\php.exe -q <?php echo "Hello world of PHP CLI!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-795405 Share on other sites More sharing options...
Xu Wei Jie Posted March 29, 2009 Author Share Posted March 29, 2009 Sorry guys, this is a noob question. Can anyone teach me how to use a shebang on both windows and unix? Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796068 Share on other sites More sharing options...
Silverado_NL Posted March 29, 2009 Share Posted March 29, 2009 Windows won't recognise a shabang and only has a very limited shell like he said, shebang doesnt work with windows systems. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796087 Share on other sites More sharing options...
Xu Wei Jie Posted March 29, 2009 Author Share Posted March 29, 2009 Actually, I have googled to this site and it says it is possible on windows. Probably I am mistaken? http://www.php-cli.com/ Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796089 Share on other sites More sharing options...
Silverado_NL Posted March 29, 2009 Share Posted March 29, 2009 well the site states it might work with CLI, but i would take thorpe's word over a website with that many spelling errors and just make a wrapper:P Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796091 Share on other sites More sharing options...
corbin Posted March 29, 2009 Share Posted March 29, 2009 Edit: I think I may have entirely misunderstood this thread.... If so, just ignore this. You can set the handler for .php files, just as the handler is set for .bat, .jpg... so on. All you have to do is associate the .php file extension with your PHP binary. Don't remember the exact steps to do it through the registry, but you should be able to do it through the Open With menu when right clicking. Then, after .php is associated with it, you should be able to just do: file.php in the command line. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796101 Share on other sites More sharing options...
Xu Wei Jie Posted March 30, 2009 Author Share Posted March 30, 2009 so if we use a shebang on unix, we just type the name of the script and it will execute? Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796560 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 Yes. That's the point of a shebang line. Quote Link to comment https://forums.phpfreaks.com/topic/150920-setting-class-paths/#findComment-796561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.