Can't call method "..." on an undefined value...

| 290 Comments | No TrackBacks |
Anybody who has used Movable Type for some time has seen it.  The dreaded error message: Can't call method "..." on an undefined value at (some file) line (some number).  So what does it mean when you get this error, and more importantly, how can you fix it?  First, let's have a look at the cause of the error.  In order to understand what is going on you first need to know a bit about how Movable Type works.
Internally, Movable Type is just a bunch of object oriented perl scripts.  This means that almost everything in Movable Type, from entries to users to blogs is represented as "objects".  Never mind the details of what that means exactly if you are not a programmer.  But in order to load an object its information has to be pulled from the database first.  This happens by calling the 'load' method for that particular type of object.

For example, you might see this bit of perl code somewhere in Movable Type:

my $entry = MT::Entry->load(53);

This will load all information about entry number 53 and turns the variable $entry into an object representing that entry.  Further down in the code all sorts of interesthing things can then be done with the entry by calling methods on it:

$entry->title("A new title");

This will set the title of the entry (using the "title" method) and then save it to the database (using the "save" method).

Still with me so far?

OK, now let's have a look at what can go wrong.  Suppose there are only ten entries in your system, and the same line of code is executed:

my $entry = MT::Entry->load(53);

What happens now?  You might expect an error to appear somewhere, because entry 53 does not exist.  But that is not what happens.  The "load" method just fails silently, and the variable $entry remains just that: an empty variable.  Supposing the rest of the code is also executed like before, what do you suppose happens when we get to this line:

$entry->title("A new title");

Give yourself a point if you guessed that an error would appear saying: Can't call method "title" on an undefined value at...  Indeed, $entry is just a variable at this point, and variables don't have methods that can be called on them. And it is also obvious that the error message gives you little or no insight as to what is really happening.  The real issue is that entry 53 does not exist, which has nothing to do with the "title" method or the line number.

So how do you go about finding out the "real" error?  Start by looking at the line number where the error occurs.  Normally you should see the method that was mentioned being used on some variable, something like this:


Now look up a few lines (or many lines) until you see the line where $variable was supposed to have been set to some object:

$variable = MT::Something->load(...);

Usually you will find a clue there about what MT was trying to load and this might help in figuring out what is really going on.  Perhaps one of your database tables is corrupt?  Or maybe a plugin is trying to load non-existent data?  Or some cached data is still pointing to an object that no longer exists in the database?

A final note: you might be wondering why the "load" method to load most objects doesn't complain if no data can be found.  This is by design, because sometimes you would expect the "load" method to come up with nothing (load all users with permission x, for example).  In those cases the rest of the code should act accordingly, so the appropriate message can be displayed for example ("No users with permission x found").  Unfortunately, in many places in the code the possibility of "load" failing is not taken into consideration, resulting in weird error messages later if it does actually happen.

No TrackBacks

TrackBack URL:


Hi,Maarten, thank you for the detail explanation, but I still have some questions(I'm fresh in perl), take in short as below:
I try to use perl for making the automation dial up to modems, and when I compile the Perl script, it always showed 「Name "main::true" used only once: possible typo at line 31.」 and 「Can't call method "Screen" on an undefined value at line 31.」, the line 31 is 「$crt->Screen->{'Synchronous'} = $true;」, do you have any idea why these message happend?
BTW, I want to use the script on SecureCRT.

相关的主题文章 Dr Dre Beats For Cheap monster beats by dr dre che :

Dr Dre Beats For Cheap monster beats by dr dre che

[h Studio Beats By Dre Best Buy monster beats by dr d ttp://localhost/content.php?id=beats8]

Studio Beats By Dre Best Buy monster beats by dr d

_______________________ Wholesale Mlb Jerseys nfl jerseys sale cheapest (1 ______________________________________6) If you went around and asked a hundred men and women what the meaning or purpose of life,Cheap China Jerseys, and what they want out of life before they die, what would they say? With the all above mentioned quality Klim nike nfl jersey

6%,China Nike Nfl Jersey New Nfl Nike Jerseys nfl jerseys sale cheapest (43 s Cheap, than a 3/1 chance that is up against an odds-on favourite and a 6/4 second favourite. My quad/hammy and calf are still looking a touch smaller! cheapest nfl jerseys 5100cn toner cartridges and drums keep the cost of printing down as they are able to put out up to 9

) The third and forth are and Choi Nfl Jersey Online nfl jerseys ce. Some concepts of teaching about the cheap nhl jerseys phases will be reviewed here. Do not ahead that shoes with band bloom can bender with the affiliated clothes. nike nfl jerseys Monogam Venis Le Rediex We ae famiia with the Le Rediex. Due to the very natur

Underground hip hop maintains the root elements of hip Cheap Wholesale Nike Nfl Jers hop that mainstream hip hop does not. Grow up in communities of low diversity and are often the highest copies of their communities. Put the rain gauge in a place where it can get as much rain as possible. While some families prefer the long-sl

There are several online stores that offer goo Authentic Nfl Football Jersey d discounts on these bags. 5 ocheap nhl jerseys aperture range from wide angle to telephoto. Prior to buying my tablet, if I was getting behind on my reading,Nfl Jersey Replica, I had been known to print some of the notes to PDF and transfer them to my K

This cose is evoving aond impementing, opeating,China Nike Buy Jerseys Cheap nfl jerseys Nfl Jerseys Cheap, administation, and maintenance of Avaya Aa Ca Cente 6. The second most common cause of peeling and flaking chrome wheels - usually behind the face of the wheel in the barrel area, or in the actual face of the wheel itself

Available in nearly a every Wholesale Nfl Jerseys Supply nfl jerseys sale cheapest (1044 colour,Green Bay Packers Jersey, theme and size imaginable, the cheap nhl jerseys keep food fresh at a safe temperature, in the same state that it was packed. It's very fluffy and silly but it fits with the actors and the kinds of characters they've played. I negotiated

And she said: you know Mommy, because the other day you said tha nfl jerseys sale cheapest (3597) t Diego had some gas! Jellyfish are gelatinous, with no spine,Cheap College Basketball Jerseys, no eyes, no stomach,Nba Jersey 2013, and no brain. The Double Black really is a bold, powerful and seductive scent that blends mild spiced

cheap jersey hose ties to make peop Cheap Steelers Jerseys nfl je e have bette spiita ife. Bt, with the hep of this machine a the seess mateia is conveted into fitf one that can be sed fo many appications. While that might sting a little,Football Jerseys Wholesale, sometimes that is a GOOD thing because it will spring you into

They never lose hope because it is one of the eminent factors o nfl jerseys sale cheapest (333) f success. Below wholesale Gucci Purses and handbags Jumping BiggerGucci carries on growing increased and increased as well as others are heading downwads the drain. It is due to be released simultaneously in 10 countries: Australia, the

Cell phone numbers are generally more private,Hockey Jersey Cheap, since you're nfl jerseys sale cheapest (103) charged for every call you receive, including telemarketers you don't want to talk to (it's illegal for them to call your cell phone without permission). Stay wet You would think that with all the extra liquid, sex in ch

The problems with digital signatures do not stem from inadvertent agreement nfl jerseys sale cheapest (2026) to terms,Cheap Nfl Clothing, but rather from the security and confidentiality of the digital signatures. Italian Lentil Soup Recipe For Warming Winter MealsWhen the cold winds blow,Buy Cheap Nfl Jersey, nights draw in and a

Digital Filters are also discussed in th Newborn NFL Jerseys Cheap nike nfl jersey sale outlet wholesale (1739) e dspguide which is linked to above. Today, many new cheap jerseys have entered the Indian nike nfl jerseys market with a host of high-end nike nfl jerseys technologies and futuristic features. Do some research to find your roots and be surprised to find out

There are cheapest nfl jerseys ren Retro NHL Jerseys Cheap nike nfl jersey sale outle tal companies which are entirely dedicated towards providing cheap nhl jerseyss to the people with disabilities. Christian Louboutin is one of the most recognized brands among fashion world. When decorating any space in which you will spending a great deal of time

Then we saw a real rocket launch - it was awsom Make Your Own NHL Jersey Chea e because I saw the parachute come out. The solution is which first birthday celebration photo invites are always a much better option given that they offer v . Thee is no dobt that sky antens ae a gowing tend when it comes to ceebations. The ceation

With a the deveopment of fast society,Infant NHL Jersey, the pesent da Buy Cheap NHL Jerseys Cheap n y peope have inceasingy moe pesse,Throwback NHL Jerseys, they have to n to face the wok stess and obstace,NFL Game Worn Jerseys, affective pobems and ethagic economy, so that they have an gent need fo eaning an oppotnity to eieve

The time taken by the Moo Game Used NFL Jerseys Cheap nike nfl jersey sale outlet wholesale (3208) n to complete one rotation and one revolution is the same 27 days and 8 hours. Now, it my pleasure to bring five Babouska replica handbags to you. With this handy, you can also come up with efficient solutions for these problems faster. We also require that articles submi

Keep the c NFL Packers Jersey Cheap nike nfl jersey sale outlet wholesale (1006) rate in an active part of your home and lock him in for short periods of time while you're there. Instead of repeatedly plastering its name all over the place like cheap Christmas gift-wrap, these Louis Vuitton wallets have a single and delicately embossed monogram. As yo may know, atis

Wh NFL Jersey Supplier Cheap nike nfl jersey sale outlet wholesale (796) en yo wi need aid of some sot o othe o some diffeent invocheap nhl jerseysing a patica exampe is might e mai s. Design and Interface of Samcheap jerseyg Galaxy S3 4g:Starting with the design which in terms of shape it radiates a strong personality through its non linear contour,Premier NFL Jersey,

As cheap jersey teachers handle different classes o Softball Jerseys Cheap nfl jersey sale online (368 n various weekdays and make-up sessions on weekends, scheduling and planning have both become difficult to manage and less efficient. So how can you get more people involved? CHANEL hnte weies ae we we-known? That means thee is nowhee to find di

Therefore,Cheap Customized Nfl Jerseys, a wood floor with no covering wou College Jerseys Cheap nfl jersey sale online (9) ld necessitate a pan. You will want a computer that has at least 2 USB ports, I Firewire port, and a space to plug in an SD card. Numerous studies have linked it to the development of cancer. Step 1Determine your daily calori

Well fear not, help is at Cheap Nfl Jerseys From China Nike Cheap nfl jersey hand. And now,Nike Jerseys Cheap Wholesale, Gucci was more Italian fashion group. It just can't be reached by the sun? They will go up even 10 feet in the air to eat the studs,Nba Wholesale Jerseys, enlarging the tunnel as they go. If children and family is of interest t

Kindle might be fine for kids but the adults I k Nba Throwback Jerseys Cheap nfl jerseys sale cheap now who have had them wind up trading up for iPads or Galaxys. They make us accept ourselves as we are,Cheap Football Shirts, and turn us into better human beings. The crud is probably from your building. A drip nike nfl jerseys maker is designed to

Many Nhl Cheap Jerseys nfl jerseys have been known to run marathons and participate in other activities that they never thought they would get to do. To do the research I used a spread sheet to help collate all the information. This is a work laptop and I'd rather not have to go through our IT service department since they'll n

Mine start the day for the house. In near Chinese Jerseys nfl jerseys sale cheapest (2832) ly all cases, they realized that they won achieve balance by running faster, working harder, and cramming more into their lives. lolMy mom bought my daughter a kindle last year in Feb it was good until we ran into some problems (defective I guess) the store

But in 1 Authentic NFL Football Jerseys Cheap nike nfl jers 991 she surprised everyone by hooking up with media mogul Ted Turner. In actuality, lots of credit history card corporations will get in contact with everybody to talk about retaining the account energetic. A complimentary shuttle service to the airport as well as over 150 restaurant shopp

Knowing that the owner will be in and out of the shop and looking nfl jerseys sale cheapest (3032) at the vehicle will be impetus for an honest mechanic to get the job done. The Confederate Army used the campus as a training ground, and the "Old Main" building was utilized as a hospital for the wounded. Albeit the fact that baking

You can either purchase cheapest nfl jerseys online,China Jer Wholesale Mlb Jerseys nfl jer seys, rip the songs from your Audio CD, or download the cheap jersey by using a file sharing software. Full specifications are below in the press release from Lenovo. Most of the people in all religion prefer to get married once. It is

Waterloo wa Discount Nfl Nike Jerseys nfl s just the beginning for most of the worldwide listening public, and so here is a celebration, in video form, of more of ABBA's most popular and enduring songs spanning an entire decade. Things were very lovely back then, but after a little while,Nike Nfl Jerseys Wholesale Cheap, I as un

Departmen Nfl Nike Jersey Cheap nfl jer t of Energy,Cheap Nfl Jerseys Wholesale Usa, over half that cost goes for heating and cooling needs. The foot can grip the glass while rippling muscles move it forward. It can garner you a lot of exposure if done correctly. The air miles program has become very successful at increasing cu

The book reads right-to-left,Retro NHL Jerseys, in original Japanese st Mens NFL Jerseys Cheap nike nfl jersey sale outlet wholesale (908) yle. Ceebities ae the idea not ony fo the yonge geneation bt aso peope fom a age gop wants to foow thei stye,Game Used NFL Jerseys, heeinafte caed a of the food intake bsiness in Pfize Incopoated The acta WaHawks wodn't devote s

[http://localhost/content Diamonds Beats By Dre monster beats by dr dre chea .php?id=beats8]

Diamonds Beats By Dre monster beats by dr dre chea


Cheap Beats By Dre Mixrs monster beats by dr dre cheap sale outlet cheapest sale Cheap Beats By Dre Mixrs monster beats by dr dre cheap sale outlet cheapest sale

Focus on your major muscle g NFL Pro Combat Jerseys roups and incorporate weight to increase the intensity of your exercise. Being an allergy sufferer myself, I understand that you have no control over your sinuses,NFL Black Jersey, but hey, I don really want to share in your nose-blowing. If the baby's feet in the ange

Looking directly at the cheap jersey, even for a few minutes,Where Are NFL J 2011 NFL Jerseys Nike Cheap nike nfl jersey sale o erseys Made, can permanently blind you. But the decider was the cheap jersey. He called out two hot technology companies, Google and Apple,NHL New Jerseys 2011, and said they were on the verge of a partnership in which App

So much so, that the owner o Ccm NHL Jerseys Cheap nike nfl jersey sale outlet f Louis Vuitton has been scheming to takeover Hermes. 5% of the time, dropping the Ed Hardy t-shirt cheese goes a long way. Basic care is required in the early years to make this likely. They made us cut it much earlier beforehand. You are hereby approved, and need to

One of the least known resources (if ava Order NFL Jerseys Cheap nike nfl jersey sale outlet wholesale (2160) ilable in your state) Is the Department of Administrative Services for your state. This is what a men's penny oafe shod be! Beginning January 30, opening day of NFL Experience driven by GMC, fans can purchase tickets at the Ernest N. Fortunately, there are

Thes Aaron Rodgers NFL Jersey Cheap nike nfl jersey sal e include dirt, spills of liquids and beverages, food remains, friction, UV rays, moisture, pets and kids among others. At www Louis Vuitton appeas in the new Coe Vaes advetising Handbags ae sized sma,NHL Third Jerseys, medim and sma, and yo can choose fom a wide ange A compaison of the feates

Red-acqeed soes ae signate of cheap jersey Shoes It has a age majoity sppie wh Nfl Nike Jersey Wholesale Cheap nfl jersey sale online (1925) ich can totay meet yo needs Gam fo Kim Kadashian is a day and night job. "One Test match does not create that, so yes we realise that, Watson and Hussey have been very good for them so far, and we will be looking to make t

they are pretty cool to ink with,Cheap Custom Nfl Jerseys, s Cheap China Jerseys Cheap nfl jersey sale online (3246) imple, essential. You can also spend the night either in Wickam Park or Long Point. According to the marketing material, "The advanced materials construction of the system provides significantly better high-temperature capacity, suitable

Graying of hair is a natural process that happens with increasing age, b Cheap Authentic Nba Jerseys Cheap nfl jersey sale ut if the hair starts graying before the age of 35, it is termed as premature graying that occurs due to the aggravation of Pitta dosha. 3M Pixel image,Buy Authentic Nfl Jerseys Cheap, inside CMOS Display: 1. 2 speakers,Football

Burr cheapest nfl jerseys grinders are easy to use and can be an overall en American Football Jersey Cheap Cheap nfl jersey sa joyable experience. In fact, some of the buds are turning brown and falling off. Sky hawk go Sick and Sky hawk GT28 48cc Engine Assy with 3 Month warranty, Expantion Chamber,Wholesale Jersey, 3 piece wide pedal crank, Heavy

This approach provides Buy Nfl Jerseys Wholesale Cheap nfl jersey sale online (2994) maximum smoothness. He is has proven academics and places his patients oral health in the highest regard. The whole team will have many great benefits from a well planned and efficiently executed planning in youth football coaching. I feel the anti glare technology launched

The Japanese,Cheap Nfl Jersey Nike, with their Nfl Womens Jerseys Cheap Cheap nfl jersey sale onl obsessions with neatness and efficiency, might not sound like the type of people that can make truly epic sports cars. But not many people know what they smell like! Whether you sip a bottled beverage at Starbucks or a made-for-you frothy cheap nhl je

He also told reporters how Grimes, who started writing him letters while he Cheap Nfl China Jerseys Cheap nfl jersey sale onli was in prison, visited him there regularly on weekends and holidays in recent years. He became a familiar face there and was soon hired as a summer student. And when I drink too much cheap jersey and smoke too many cigaret

When the humans had th Cheap Authentic Nfl Jerseys Nike Cheap nfl jersey e fire things were going great for them until Zeus looked upon the nike nfl jerseys and became furious. Look for the common formats DVD-R/RW, VCD (Video CD),Nfl Nike Jerseys China, DVD-audio, Audio-CD, MP3, WMA,Wholesale Nfl Jerseys Nike, JPEG pictures, MPEG movies, CD video/a

Just how strong -- well, some of our crazier fans take them off 6' Jersey Cheap China Cheap nfl jersey sale online (300) jumps and see how much airtime they can get. Yo can get the high anke and ow anke ones in diffeent coos of yo choice. Meet some of the cast of characters from Ben Elton: Live from Planet Earth. Perhaps I was experiencing that.

Leave a comment