archive-com.com » COM » B » BENRAMSEY.COM

Total: 425

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Showing All Declared Classes, by Ben Ramsey
    list Boy was I wrong I ended up being the stupid person and I learned a new and interesting trick It seems that I m going to have to sit down and read the PHP manual through in full It s chock full of interesting functions that I know nothing about but that are extremely useful In fact I learn something new everyday Today was one such day I learned about the existence of the get declared classes function This function exposes all the classes that that are currently defined it returns an array with their names Using this array you can expose the methods of each class If your application script has no user defined classes you ll get a good look at all the intrinsic classes of your PHP installation The following function uses get declared classes in conjunction with get class methods to write out all defined classes and their methods php function show all declared classes classes get declared classes foreach classes as class echo class n n methods get class methods class foreach methods as method echo t method n echo n n Just call it with show all declared classes and voila You ll

    Original URL path: https://benramsey.com/blog/2004/02/showing-all-declared-classes/ (2016-04-26)
    Open archived version from archive


  • Bloomba Over Mozilla?, by Ben Ramsey
    search features The powerful search feature makes folders largely unnecessary says Overholt Bloomba has several major drawbacks however as she mentions in her article These are the inability to use IMAP Bloomba is POP3 only the lack of a calendar task feature and a 49 95 price tag Each of these features and more excluding the hefty price tag may be found in Mozilla Thunderbird a free client that she failed to mention I can t imagine why she overlooked Mozilla Thunderbird It used to be Netscape so it s not entirely new or foreign Plus it s open source and free and offers many extensions with more on the way that by far overshadow the features in Outlook and Bloomba Thunderbird allows connections to IMAP servers Thunderbird has a good search feature There are excellent junk mail filters If a calendar is what you want then there s an extension for Thunderbird that provides calendar and task list functionality In fact since the application is open source there are many more extensions to choose from with more on the way due to the fact that there is a community of developers creating them Clearly the better alternative to the

    Original URL path: https://benramsey.com/blog/2004/02/bloomba-over-mozilla/ (2016-04-26)
    Open archived version from archive

  • What the GPL?!, by Ben Ramsey
    use However there is a con to this your code may benefit those money grabbing capitalists on Wall Street But that s not the biggest con Quite possibly the most important problem with the PHP License is that it is incompatible with the GPL What does this mean It means that you can t distribute code licensed under the PHP License with your GPL ed application For this reason the MySQL libraries will no longer be bundled with PHP 5 nor will MySQL support be enabled by default MySQL s libraries are licensed under the GPL which as stated before is in conflict with the PHP License Because of this conflict the decision was made to completely separate MySQL from PHP This does not mean that end users cannot use MySQL in their PHP installations It just means that MySQL will no longer be turned on by default nor will the MySQL functions be distributed with PHP If you re reading this and just now learning about it don t worry you probably won t be affected too much since the MySQL libraries come bundled on most systems already They re not too difficult to install at any rate So if PHP couldn t include MySQL libraries because of a license conflict then certainly I couldn t include PHP licensed code in my project I needed to find a solution I posted a message to the PHP general mailing list asking what others have done to include PEAR packages released under the PHP License in their GPL ed applications I didn t receive many responses but I did receive two different types of responses The first type told me to go ahead and include the code in separate files Those files would remain under the PHP License while my code would be under the GPL That sounded sensible enough but it didn t seem to get around the fact that I would be distributing PHP licensed code under an overall GPL ed application The second type of answer told me not to distribute the PEAR packages with my application but to include a list of required libraries with links for users to download them This definitely gets around the licensing issue but it s not too inviting for potential users of my application to download twenty or so PEAR packages and install them in the correct locations for my application to find them There had to be another way and there was I found my answer when I went to the source I sent an e mail to the Free Software Foundation FSF the folks behind the GNU GPL They were very prompt in their response answering me in less than an hour s time It also seems that the answer is on their Web site under the FAQs for the GPL Unfortunately the site has many FAQs and they are not easy to sift through nor did I know which question I was asking This is why I did

    Original URL path: https://benramsey.com/blog/2004/02/what-the-gpl/ (2016-04-26)
    Open archived version from archive

  • PHPCommunity.org, by Ben Ramsey
    response to the announcment and set up a wiki at PHPCommunity org Since then the site following has grown by leaps and bounds though the site lauch may not be for quite some time This is an exciting opportunity for the PHP community and I m excited to be involved The advent of this community site has inspired me to finally put this Web site together and start doing what

    Original URL path: https://benramsey.com/blog/2004/02/phpcommunityorg/ (2016-04-26)
    Open archived version from archive

  • PHP at 20: From pet project to powerhouse, by Ben Ramsey
    Miami Lerdorf quipped In 1995 I thought I had unleashed a C API upon the Web Obviously that s not what happened or we d all be C programmers In fact when Lerdorf released version 1 0 of Personal Home Page Tools as PHP was then known the Web was very young HTML 2 0 would not be published until November of that year and HTTP 1 0 not until May the following year NCSA HTTPd was the most widely deployed Web server and Netscape Navigator was the most popular Web browser with Internet Explorer 1 0 to arrive in August In other words PHP s beginnings coincided with the eve of the browser wars Those early days speak volumes about PHP s impact on Web development Back then our options were limited when it came to server side processing for Web apps PHP stepped in to fill our need for a tool that would enable us to do dynamic things on the Web That practical flexibility captured our imaginations and PHP has since grown up with the Web Now powering more than 80 percent of the Web PHP has matured into a scripting language that is especially suited to

    Original URL path: https://benramsey.com/articles/php-at-20/ (2016-04-26)
    Open archived version from archive

  • Mocking Hard Dependencies in Legacy Code, by Ben Ramsey
    getAddress method to ensure it returns an Address object but how are we going to do that The address property is protected so we can t easily set it An easy change is to set it public Then after instantiating a User we can set an Address to it and assert that getAddress returns it But what if we can t do that What if our interface needs to stay the same Well we can use reflection to change the accessibility of protected properties so let s try that public function testGetAddressIsAlreadySet user new User user setAddressId 123 reflection new ReflectionClass User property reflection getProperty address property setAccessible true property setValue user new Address 123 this assertInstanceOf Address user getAddress Great Now our coverage is better and we ve asserted the getAddress method returns an Address object The problem is we didn t test whether the getAddress method sets the address property and we have an ugly untested line in our code coverage report that s keeping us from hitting that glorious 100 coverage mark Address is a hard dependency We can t change it Since the object is instantiated within the method there s no way for us to inject a test double so we can t test it without fear of causing side effects In this simple example the side effects may be harmless maybe it simply makes a SELECT query against a database to retrieve data but this turns into an integration test and we don t want to test our integration with the database We only want to test our code One way to handle this is to admit defeat and quietly sweep away the untested lines under the rug by wrapping them with codeCoverageIgnoreStart and codeCoverageIgnoreEnd annotations This is what I used to do when encountering code that appeared untestable codeCoverageIgnoreStart if this address null this address new Address this getAddressId codeCoverageIgnoreEnd In researching approaches to testing code I stumbled accross the Mocking Hard Dependencies section of the Mockery documentation Mockery provides the ability to inject a test double class into the scope of the running test and when your code under test invokes that class with the new keyword or a static method it uses your mock This works best when using an autoloader in your tests If any code is encountered that uses a class that hasn t yet been loaded it invokes the autoloader to load the class Mockery allows you to overload this behavior by injecting a class with the same name so that when the class is encountered in your code it is already loaded and the autoloader doesn t try to load your real class If you re using Composer s autoloader with your tests you re all set This is not without some problems though If previous tests have already autoloaded the class then Mockery won t be able to inject a class with the same name This will result in an error Mockery Exception RuntimeException Could not

    Original URL path: https://benramsey.com/articles/mocking-hard-dependencies/ (2016-04-26)
    Open archived version from archive

  • Debugging Zen, by Ben Ramsey
    Grow Your Intuition 6 Simple Steps Suzan Bond says that we shut off our intuition when we answer questions with I don t know She goes on to say When you stop using this phrase as much you will open up your intuition You ll be able to see more possibilities rather than limitations It s not wrong to admit lack of knowledge in an area and I m not advocating that you make up answers but the truth is that you may already know the solution Your brain already has the data it needs Slow down Take a breath Ponder on it Let your intuition speak to you If you have trouble finding a solution ask yourself what may be blocking you from seeing it Don t accept that you don t know the answer Accept that you must discover the answer The problem is in your code Here s a humbling but crucial notion It s never fun to accept the blame for something so it s easiest to point fingers at someone or something else This third party library or framework is terrible John wrote this spaghetti code three years ago and it s awful This programming language is a nightmare Let s face it developers are proud folks and masters of hyperbole I have learned though that the problem is most often found right in your own code so it s best to begin with that assumption Very early in my career I worked with a developer we ll call him John who always blamed someone else s code when he found a bug He loved doing this so much that he would leap from his desk giggling and run into my office to boast about finding a bug in some third party library or even in the programming language we were using John loved being able to say that the language was faulty and that he was responsible for finding it out On more than one occasion he had the programming language s bug report form open and filled out before I was able to catch him and force him to readdress the issue by carefully looking at his own code Every time his code was at fault When you start with the assumption that it s someone else s code that has the problem then you re hurting yourself in several ways First of all you re impeding your own ability to find the real problem because you start by looking in the wrong place This costs you time Secondly you re setting yourself up to look like an buffoon when it turns out your code was the problem all along and you wasted time energy and resources trying to blame something else Lastly you hurt your reputation as a problem solver by passing the buck When you start with the assumption that the problem is in your code then you display humility and leadership by accepting the responsibility to solve the problem If

    Original URL path: https://benramsey.com/articles/debugging-zen/ (2016-04-26)
    Open archived version from archive

  • Simplifying Commerce for Small Business, by Ben Ramsey
    You still need your own SSL certificate but those are much cheaper these days Calculate Many businesses choose to avoid the hassle of calculating sales tax on the front end and bake it into the cost of the good or service but this means there s hassle on the accounting side at the end of the year Your accountant must then determine where you have nexus a fancy term for regions where you are required to collect sales tax examine the shipping address of everyone who bought from you to see if they need to calculate sales tax and if needed calculate the sales tax for that jurisdiction or guess at it and hopefully overpay SpeedTax recently acquired by CCH provides a service with an easy to use API to reduce and eliminate this hassle You can set up your SKU s within the SpeedTax system and categorize them so that SpeedTax will know how to calculate the sales tax according to each jurisdiction s laws Then you specify where you have nexus When you send a request to the SpeedTax API you include the SKU and the shipping address of the customer SpeedTax takes care of the rest and gives you back the appropriate sales tax that you should collect for that jurisdiction Fulfill Fulfillment includes three different processes none of which are easy for a small business to perform alone The first is calculating shipping fees This can be done online but you have to make decisions about which provider to use USPS UPS FedEx DHL c and integrate with their API APIs if you choose multiple providers The second is determining whether you have the inventory required to fulfill the order The third is actually picking packing and shipping the product Most small businesses do this on their own at first but if you want to scale your business you ll need to outsource this so you can focus on running your business instead of shipping your product Shipwire provides all three of these services Their APIs calculate shipping rates for a variety of vendors which you can provide to your users as options and you can store inventory within their global warehouses so you can query their APIs to determine whether you can actually fulfill an order based on inventory available Furthermore since you store your product in Shipwire s warehouses they will pick pack and ship your product based on API calls you make to their system Seize the Opportunity When you or your clients are out and about either at trade shows and conventions or just through the course of normal everyday life accepting payments whenever and wherever the opportunity arises is important Square provides a credit card reader and app for iOS and Android devices that allows you to swipe and accept credit cards virtually anywhere They don t provide any APIs so they re not an application integration tool but if you have clients who need to accept payments online then they

    Original URL path: https://benramsey.com/articles/simplifying-commerce/ (2016-04-26)
    Open archived version from archive



  •