Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

At the risk of getting a down vote I am going to ask this question to see if anyone can help me. I have been staring at this for a while and I can't figure it out.

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) on line 130

function pdf($type=null){                                                                                                                                                                                                              
    //get default or create a type                                                                                                                                                                                                     
    $data = $this->storeSessionData(                                                                                                                                                                                                   
        array(),                                                                                                                                                                                                                       
        'SalesComp',                                                                                                                                                                                                                   
        $this->variables                                                                                                                                                                                                               
    );                                                                                                                                                                                                                                 

    $type = ($type)? $type : $data['type']; //this is line 130                                                                                                                                                                                            

    $this->set('data', $this->report('store', 'year', 3, $type));                                                                                                                                                                      

    $this->set(                                                                                                                                                                                                                        
        'districtTitle',                                                                                                                                                                                                               
        array('N' => 'North', 'S' => 'South')                                                                                                                                                                                          
    );                                                                                                                                                                                                                                 
    $districts = $this->Store->find(                                                                                                                                                                                                   
        'list',                                                                                                                                                                                                                        
        array(                                                                                                                                                                                                                         
            'fields' => array('Store', 'District'),                                                                                                                                                                                    
            'conditions' => array('NOT' => array('District'=> 'O')                                                                                                                                                                     
            )                                                                                                                                                                                                                          
        )                                                                                                                                                                                                                              
    );                                                                                                                                                                                                                                 
    $this->set('districts', $districts);                                                                                                                                                                                               
    $supervisor = $this->Store->find(                                                                                                                                                                                                  
        'list',                                                                                                                                                                                                                        
        array('fields' => array('Store','Supervisor'),                                                                                                                                                                                 
              'conditions' => array('NOT' => array('District'=> 'O')                                                                                                                                                                   
              )                                                                                                                                                                                                                        
        )                                                                                                                                                                                                                              
    );                                                                                                                                                                                                                                 
    $this->set('supervisor', $supervisor);                                                                                                                                                                                             

    $this->set(                                                                                                                                                                                                                        
        'supervisors',                                                                                                                                                                                                                 
        $this->Supervisor->find(                                                                                                                                                                                                       
            'list',                                                                                                                                                                                                                    
            array('fields' => array('Supervisor','ShortName')                                                                                                                                                                          
            )                                                                                                                                                                                                                          
        )                                                                                                                                                                                                                              
    );                                                                                                                                                                                                                                 
    $title = ($type == 'sales')?                                                                                                                                                                                                       
        'Sales Comparison Report':'Fuel Comparison Report';                                                                                                                                                                            
    $this->set('title', $title);                                                                                                                                                                                                       
    $this->layout = 'pdf';                                                                                                                                                                                                             
    $this->render();                                                                                                                                                                                                                   


}  
share|improve this question
3  
Which line in this corresponds to line 130? Could be helpful – StephenTG Jul 26 '13 at 20:34
5  
the one marked //this line is 130 – Nicholas Smith Jul 26 '13 at 20:34
    
Ah, I see. Wasn't checking the comments in the code... – StephenTG Jul 26 '13 at 20:36
1  
It may have something to do with all the excess whitespace at the end of the lines. I've seen it break heredoc strings before... – dialer Jul 26 '13 at 20:39
1  
The error suggests there are mismatched quotes somewhere. If you're using Emacs, use M-x find-unbalanced-parentheses. And if you have syntax highlighting enabled, you should be able to see the wrong colors. – Barmar Jul 26 '13 at 20:59
up vote 1 down vote accepted

The error suggests mismatched quotes or brackets somewhere. Unfortunately, when this happens, the line number in the error message may be some totally unrelated line -- it's just the first place where the compiler notices that the syntax is no longer valid. The error is actually somewhere before the code snippet in the question, so it's impossible for me to pinpoint it. Syntax highlighting in code editors can help in finding the mismatch.

share|improve this answer
    
I finally found the error it was a mismatched quote in the previous function so Barmar is completely right. My emacs syntax did not pick up the mismatch for whatever reason. However, I fired up eclipse and it picked it up right away. I am not sure what that says for the Emacs verses Eclipse debate but all is well that ends well. I want to thank everyone for there help. – Nicholas Smith Jul 26 '13 at 21:34
    
Emacs has long had problems with PHP because of the way it's mixed with HTML. – Barmar Jul 26 '13 at 21:35
    
This is a different conversation for a different thread but there is no html in that page. It really doesn't have any excuse. However, I have to say it usually catches errors. Well it doesn't catch them so much as not format correctly and I notice them. Additionally, I love the way it formats my code. I use a lot of closure type idioms and it steps the code very well. Anyway thanks for the help. – Nicholas Smith Jul 26 '13 at 21:45

You can find all php tokens here:

http://php.net/manual/en/tokens.php

There's 2 things about the marked line:

  1. PHP is a scripted language with a VERY complicated syntax in reality. It might look simple, but in comparison to C or the like it's very complicated, and only because there where so many small (and many times incoherent) changes made over the years, and some things can't be changed anymore without breaking backwards compatibility. One of those things is handling of parantheses - PHP does not handle these in a mathematical way, but treat them specially depending on context. This means you should get rid of them in the marked line (there is no need for them in the first place either way)

  2. "Invisible" (i.e. UTF8) whitespaces - these are source for many "strange" problems, especially if you develop on a mac (press alt + space). Easiest way to fix them: Retype the line. And DON'T try copy & pasting it, because you will copy the whitespace as well.

Also I would change the line to

if (! $type) $type = $data['type'];

I hope you know which values evaluate falsy in php, because it's not only NULL (you can find a list here: http://php.net/manual/en/language.types.boolean.php )

On a sidenote: PHP was developed as a simple way to write templates, so maybe you might want to have a look at some compiled programming languages if you want to build complex logic (C for example, which is by far simpler than PHP, and I've been doing PHP for more than 6 years now)

share|improve this answer
    
if (! $type) $type = $data['type']; did not work. Still getting an error and I have delete the space in between the code with no luck – Nicholas Smith Jul 26 '13 at 20:46
    
If it doesn't work, add linebreaks. You can break at nearly every position, and it will give you a more accurate error position. E.g. go through the lines before 130, 130, and the ones after, and break them apart onto multiple lines. – griffin Jul 26 '13 at 20:52
    
that is a great idea – Nicholas Smith Jul 26 '13 at 20:55
    
I'd just consider to view it in an hex editor… – bwoebi Jul 26 '13 at 20:56

Try replacing

$type = ($type)? $type : $data['type'];

With

$type = $type ? $type : $data['type'];

I doubt that it makes any difference, but maybe a space between the variable named $type and the question mark is needed. For more information about this, check the PHP docs on the ternary operator.

share|improve this answer
    
No it made no difference – Nicholas Smith Jul 26 '13 at 20:48
    
@NicholasSmith also remove and retype the lines before and after line 130. Your editor might be confused, and display a wrong line as line 130. – dialer Jul 26 '13 at 20:49
    
@dialer If you don't know anything about this form of PHP, then you shouldn't be commenting – Daryl Gill Jul 26 '13 at 20:55
2  
@DarylGill What is your problem? Either Emacs or the PHP interpreter might interpret a particular whitespace character, such as a sole \r, as a newline, adding to the line count, while the other one does not, thus resulting in a different line number for interpreter and editor. – dialer Jul 26 '13 at 20:57
    
Actually, @dialer is correct here. The editor might be reporting an error for a different line so make sure there's no whitespaces confusing it. – federicot Jul 26 '13 at 20:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.