13

Sometimes I do not want to do anything.

I just want to have a statement so I can put break point.

In c and objective-c we have while (false);

Say I want to break a function

-(void)viewDidAppear:(BOOL)animated
{

    [super viewDidAppear:animated];
    self.navigationItem.leftBarButtonItem=nil;
    self.navigationItem.rightBarButtonItem=nil;


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateDisplays) name: NotificationUpdateArroworLocation object:nil];

    PO(self.tableView.indexPathForSelectedRow);
    while(false);//I put break point here so program stop here.
}

In .net we have donothing (Not sure Did I make that up?).

What should we use in PhP?

Cookie Guru
  • 397
  • 2
  • 10
user4234
  • 1,523
  • 1
  • 20
  • 37
  • Did I read you right? You want to put a breakpoint in PHP? – kmkaplan Jan 09 '13 at 09:03
  • 2
    Why don't you use "while(false);" too? – skurton Jan 09 '13 at 09:04
  • Well, I suppose I can put in regular places. Sometimes I want more control of where the breakpoint is. Check the objective-c code I wrote. I could do break point at PO(self.tableview.indexPathforSelectedRow). However, I prefer to break one line after it. Nah I use noop. Which is while(false); – user4234 Jan 09 '13 at 09:04
  • @skurton, I didn't think about it. I think in PhP while(false) should be followed by {} or something. – user4234 Jan 09 '13 at 09:05
  • @skurton if you're sure that work it can be the answer. You can turn that into an answer. I'll check that once I program in PhP again. – user4234 Jan 09 '13 at 09:05
  • 2
    Why should there be a need for a dummy function? If you have a decent IDE you should be able to put the breakpoint on the closing curly bracket. – pritaeas Jan 09 '13 at 09:09
  • @kmkapla - what's the problem with that? You can debug PHP just as easily as any other language. – SDC Jan 09 '13 at 09:14
  • @SDC It’s a long time since I last did some serious PHP. What debugger exists? I will be happy to try them. – kmkaplan Jan 09 '13 at 09:17
  • I used zend. Yea I sometimes try the breakpoint at closing curly bracket not sure where it really breaks. – user4234 Jan 09 '13 at 09:18
  • 1
    @kmkaplan - Zend provide a debugger, but [xDebug](http://www.xdebug.org/) is the more commonly used one. I certainly wouldn't contemplate doing any serious dev work without a debugger and all the other standard testing tools. – SDC Jan 09 '13 at 09:34
  • @SDC thank you, I will checkout this xDebug stuff. – kmkaplan Jan 09 '13 at 09:56
  • This doesn't answer the full question (about noop) but for setting breakpoints where there isn't a line suitable to attach one to, I usually use `xdebug_break()` – Tomeh Aug 01 '18 at 12:44
  • What do you want to achieve with that? You can put a breakpoint on any line – Nico Haase Dec 17 '21 at 20:39

3 Answers3

15

You can use same trick and a lot of other features:

<?php
    while (false);
    // or empty output
    echo '';
    // or any expression without side effects
    5 + 5;

If you use XDebug, you can call xdebug_break() function directly in any place.

Alex
  • 633
  • 1
  • 5
  • 10
11

Would

assert(true);

be enough to attach a breakpoint to?

For the dev environment, assertions should be compiled and executed. For the prod environment, assertions should probably not be compiled nor executed. So you can leave them in. Which is useful!

http://www.php.net/manual/en/function.assert.php

Richard A Quadling
  • 3,769
  • 30
  • 40
2

For PHP I use semicolon with a comment just to make it more explicit:

; // noop

wikipedia says a lone semicolon in its own line was a classic way of doing it in C as well.

jerome
  • 51
  • 3
  • Please add some explanation to your answer by editing it. Would XDebug hold at this line if you put a breakpoint on it? – Nico Haase Dec 17 '21 at 20:39